Click here to Skip to main content
15,991,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

if we create user define stored procedure with the prefix of sp_, does it effect on performance? it will check in master database first or user define database?
Posted

If a stored procedure name begins with “SP_,” then SQL server first searches in the master database and then in the current session database. Searching in the master database causes extra overhead and even a wrong result if another stored procedure with the same name is found in master database.

SQL Server always looks for a stored procedure beginning with sp_ in this order:

1. The stored procedure in the master database.
2. The stored procedure based on any qualifiers provided (database name or owner).
3. The stored procedure using dbo as the owner, if one is not specified. Therefore, although the user-created stored procedure prefixed with sp_ may exist in the current database, the master database is always checked first, even if the stored procedure is qualified with the database name.

Important : If any user-created stored procedure has the same name as a system stored procedure, the user-created stored procedure will never be executed.
 
Share this answer
 
v2
Comments
ProEnggSoft 30-Mar-12 1:59am    
Nice explanation. +5
member60 30-Mar-12 2:53am    
thank you
Yes it will effect the performance, it will slow down the execution and also search system procedure first!!!
 
Share this answer
 
Comments
Chandan Aryan 27-Mar-12 8:41am    
If Handy use USP_ instead of sp_ .
[no name] 27-Mar-12 8:59am    
This is your personal opinion. It should be determined by coding standards and doesn't have to be USP, and can still be sp, without the underscore.
Chandan Aryan 27-Mar-12 9:28am    
Right, its just for the demarkation from the system Procedures!!!
"We recommend that you do not create any stored procedures using sp_ as a prefix. SQL Server uses the sp_ prefix to designate system stored procedures."

http://msdn.microsoft.com/en-us/library/ms190669.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900