question

Steve Jones - Editor avatar image
Steve Jones - Editor asked

Using sp_ in procedure names

I have heard that I should not use sp_ at the beginning of stored procedure names. I'm wondering why not as this seems like a great convention for those objects.

stored-proceduresbest-practice
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
Nice question there - lots of people need this tip!
0 Likes 0 ·
Jim Orten avatar image
Jim Orten answered

See this

http://msdn.microsoft.com/en-us/library/ms190669%28SQL.90%29.aspx

"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. The name you choose may conflict with some future system procedure. If your application uses nonschema qualified name references and your own procedure name conflicts with a system procedure name, your application will break because the name binds to the system procedure, not your own."

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jim Orten avatar image Jim Orten commented ·
I just like the rule that, if I see a procedure named with sp_ I know its a system procedure.
1 Like 1 ·
Tom Staab avatar image Tom Staab ♦ commented ·
I agree it's better to avoid this situation, but it's also yet another reason to use two-part names (schema.object). For more on that, see this other question: http://ask.sqlservercentral.com/questions/1784/dbo-database-owner-in-select-statement.
1 Like 1 ·
Fatherjack avatar image
Fatherjack answered

We use a standardised naming convention for all objects we create in any databases we administer. It ensures that our objects dont have any chance of colliding with system developments from 3rd party vendors or Microsoft and it ensures they also sort nicely if you view them in the SSMS object browser or can be located in system tables ... we use cx_usp_ProcedureName, cx_uvw_ViewName, cx_utr_TriggerName (for procedures, views and triggers respectively) and so on for other objects.

When reading code you can easily get into the groove of seeing sp_... for system procedures and cx_usp... for homegrown ones

Jonathan

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sp_lock avatar image
sp_lock answered

There is also a small performance hit (if you dont fully qualify the sp when calling it).

SQL Server will search the master database 1st to see if it exists there and then it will search the user database

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Mark Allison avatar image Mark Allison commented ·
Indeed that's one of the reasons I recommend not to use sp_
0 Likes 0 ·
Alvin Ramard avatar image
Alvin Ramard answered

From day 1 I have been naming my stored procedures using "usp_" (user stored procedure).

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.