Click here to Skip to main content
13,147,376 members (27,682 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 17 Apr 2012

Stored Procedure Naming Conventions

, 17 Apr 2012
Rate this:
Please Sign up or sign in to vote.
It is recommended that stored procedures shouldn't be prefixed with sp_ for two simple reasons.

Why Shouldn't We Begin a custom/user-defined Stored Procedure Name with sp_?

Ever wondered why we don't (or shouldn't, if you do) prefix procedures with an sp_?

As a primarily .NET developer, while doing any database work, earlier I hadn't paid much attention to why all stored procedures in the company where I worked in, began with a prefix of "p". So we would name them along the lines of "p_GetXyzDataByParam1Param2". Obviously, I could see that "p" is the convention in the company, but would it cause any impact if we name them the way system procedures are named (i.e., sp_? Turned out, that yes, it could.

We do know that the system stored procedures are named with _sp, and are stored in the master database. But if any stored proc does start with an sp_, SQL Server tries to find any such proc in the following order:

  • in the master database
  • based on qualifiers like database name or owner
  • using owner dbo if it's no owner is specified

In other words:

  1. The master database is always checked first, even if the proc is qualified with the db name.
  2. If any user defined stored proc has the same name as a system procedure, the system proc will be executed (and the user proc will never be executed).


It is recommended that stored procedures shouldn't be prefixed with sp_ for two simple reasons:

If a user-defined stored procedure has the same name as a system stored proc, the user-defined procedure will never be executed.

The master db will always be checked first because of the prefix of sp_.

  • Possible conflict of user created stored procedures with system stored procedures
  • For performance



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


About the Author

My Tech World
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionGood. Pin
ZamirF18-Apr-12 9:54
memberZamirF18-Apr-12 9:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170915.1 | Last Updated 17 Apr 2012
Article Copyright 2012 by My Tech World
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid