• subscribe
November 20, 2001 12:00 AM

Tip: Always Qualify Stored Procedure References

SQL Server Pro
InstantDoc ID #23013

Qualifying the owner of an object when you reference it is always a good idea, even when SQL Server's default name-resolution rules don't require the qualification. When you use SQL Server Profiler to generate the SP:CacheMiss event, as we did in the Q&A "Should I Use the sp_ Prefix for Procedure Names?" page 21, you'll see a slight performance gain when you fully qualify stored procedure names as you execute them. To create an example that illustrates the value of qualifying object owners, follow these steps:

  1. Create a login called Test that's a user in tempdb.


  2. Create the dbo.Select1 procedure that Listing 1, page 21, shows.


  3. Run the command grant exec on Select1 to test to set the appropriate permissions.


  4. Use the Test login to log in to the server on a new connection, and change your current database context to tempdb.


  5. Be sure that the Profiler trace is running. (You create the trace by following the steps in "Should I Use the sp_Prefix for Procedure Names?")


  6. Press Ctrl+Shift+Delete to clear all events in the Profiler window.


  7. Run Select1 and notice the generation of an SP:CacheMiss event.


  8. Run dbo.Select1 and notice that it didn't generate an SP:CacheMiss event.

Because the procedure doesn't generate an SP:CacheMiss event, SQL Server doesn't need to create the compile lock that "Should I use the sp_ Prefix for Procedure Names?" describes, so performance isn't degraded. For more information about qualifying stored procedure names, see the Microsoft articles "INF: Troubleshooting Stored Procedure Recompilation" (http://support.microsoft.com/support/kb/articles/q243/5/86.asp) and "INF: SQL Blocking Due to COMPILE Locks" (http://support.microsoft.com/support/kb/articles/q263/8/89.asp).



ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here
  • SP1?
    I know there is a SP1 for SQL 2008 R2 available....and there is a "feature pack" as well... ...
  • SQL database mirroring
    I have SQL Server 2008 R2 Enterprise 64bit on Windows 2008 R2 Enterprise 64bit.  Each SQL Server has...
  • Dell Compellent Disk Drive
    Does anybody has experience with Dell Compellent Disk Drive? Basically, this system manages all disk...
  • Sql server performance tuning
    I need to find a tool that help me to optimize sql server,queries,improve the performance and solve ...