Home > Blogs > And that's why you craft your queries very carefully

And that's why you craft your queries very carefully

By  Oct 10, 2007

Topics: Data

The other day I saw a question regarding re-use of query plans. The developer was using "exactly the same" query in two places, but the query plan wasn't being reused - there were a lot of recompiles.

In fact, the queries weren't the same. One had an extra space in a strategic location. That caused the query processor to view them differently, and recompile the statement.

While we're on the subject, it's always good practice to prepend the owner name (or schema in 2K5) to your queries:

EXEC production.usp_myproc

instead of

EXEC usp_myproc

Doing it the first way saves SQL Server the trouble of evaluating whether the object is unique to a database, and which owner (schema) to use.

Become an InformIT Member

Take advantage of special member promotions, everyday discounts, quick access to saved content, and more! Join Today.