Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Don't prefix your table names with tblSQL Server 2008 R2 Datacenter and SQL Server 2008 R2 Parallel Data Warehouse Editions Announced »
    comments

    When SQL Server executes a stored procedure, it first checks to see if it is a built-in stored procedure (system supplied). It checks the master database for the existence of this procedure. If the procedure is not found, it will search the user database. It doesn't sound like much, but in a high transaction environment, the slight performance hit will add up.

    Also, consider what would happen if Microsoft decides to ship a system stored procedure with the same name as the procedure you wrote. Suddenly, your procedure will stop working and the one supplied by Microsoft will be executed instead. To see what I mean, try creating a stored procedure in your database named sp_help. When you execute this stored procedure, SQL will actually execute the one in the master database instead.

    How to detect this problem:

    1. Select  *
    2. From    Information_Schema.Routines
    3. Where   Specific_Name Like 'sp[_]%'

    How to correct it: To correct this problem, you will need to identify all procedures named this way, and then change the name of the procedure. There are far greater implications though. Some stored procedures are called by other stored procedures. In cases like this, you will need to change those stored procedures too. Additionally, you will also need to change your front end code to call the procedure with the new name.

    Level of difficulty: medium to high. The level of effort required to correct this problem can range from medium to high, depending on how many procedures you have than require a name change.

    One possible strategy you could use to help resolve this problem would be to rename the procedure, and then create a procedure with the original name. This procedure could write to a log file, and then call the original procedure. This strategy allows your application to continue working (albeit a little slower because of the logging). You can then determine which application ran the procedure and change the name of the call.

    Level of severity: Moderate

    About the Author

    George has been developing software professionally for 19 years, first for the department of defense, and then for various other companies. In 1998, George started his software company, Orbit Software, specializing in School Bus Transportation software. His specialty is refining SQL Server queries to deliver optimal performance.
    Social SitingsTwitterLTD RSS Feed
    Instapaper

    12 comments

    Comment from: Natas [Member] Email
    Natas Ouch...I didn't know this...there are tons of procs that start with sp_ in our databases

    What do you recommend they should start with? My triggers start with tr, tables start with tbl, views start with vw...maybe usp_ (for user stored proc)?
    11/04/09 @ 08:37
    Comment from: George [Visitor] Email · http://www.twitter.com/gvee
    George @Natas - the answer is to not prefix your object names with this needless stuff in the first place!

    For instance, we now have several views in a legacy database that have the prefix of tbl_ because we had to make changes to the objects for performance reasons without affecting the original application.

    Your objects should **describe** what the object does or contains, not what type of object it is.



    @GeorgeMastros - Nice article. This is a point I can't hammer home hard enough to our devs!
    11/04/09 @ 09:10
    Comment from: SQLDenis [Member] Email
    SQLDenis It can be worse how about this gem


    CREATE TABLE tblEmployee (
    intID int identity not null,
    strLastName varchar(255) not null,
    strFirstName varchar(255) not null,
    dtmBirthDate datetime null
    mnyAnnualSalary money null
    ......
    .....
    ....
    ...
    ..
    .)
    11/04/09 @ 09:37
    Comment from: Naomi Nosonovsky [Member]
    Naomi Nosonovsky Good point
    11/04/09 @ 18:29
    Comment from: dogtacocatgod [Member] Email
    dogtacocatgod I am glad you wrote this, I will print this out and put this on my co-workers desk while he steps away because he names all his stored procedures like that
    11/04/09 @ 18:59
    Comment from: genomon [Member]
    genomon "One possible strategy you could use to help resolve this problem would be to rename the procedure, and then create a procedure with the original name. This procedure could write to a log file, and then call the original procedure."

    Another is to right click on the procedure and click on "View Dependencies".
    11/05/09 @ 10:27
    Comment from: George Mastros (gmmastros) [Member]
    George Mastros (gmmastros) genomon,

    The dependencies list is not always reliable. It has to do with deferred name resolution and the order in which you create your objects.
    11/05/09 @ 15:30
    Comment from: George Mastros (gmmastros) [Member]
    George Mastros (gmmastros) Just to be clear...

    If there's anything in the dependency list, then those things would need to be modified. The problem is that the dependency list can be incomplete, giving you a false sense of security that you modified all the code that needed to be modified.
    11/05/09 @ 15:37
    Comment from: Irina [Visitor]
    Irina To SQLDenis: What is actually wrong with naming table colomns like that. I have never thought of doing it that way but... does it affect something?
    11/09/09 @ 20:21
    Comment from: George Mastros (gmmastros) [Member]
    George Mastros (gmmastros) Irina,

    There is no REAL problem with using hungarian notation for your column names. No problems as far as the database is concerned.

    The problem occurs when humans are expected to write code for the table. If you look at the column names Denis used, they are all self explanatory regarding the data type. There's an ID (int), a couple names (strings), a BirthDate (DateTime), AnnualSalary (Money). Using a 3 letter prefix on your names does not really help anything, and actually makes the code harder to read.
    11/10/09 @ 06:58
    Comment from: SQLDenis [Member] Email
    SQLDenis Irina the problem with a name like this

    mnyAnnualSalary

    is that when 2 years later you decide to change the datatype to decimal(16,4) most people don't change the column name since it might break all kind of code so now the mny doesn't make sense anymore

    these days with syntax coloring and intellisense nobody should name their columns or tables like that anymore

    Even in .NET Hungarian Notation is not recommended anymore for objects
    11/17/09 @ 10:29
    Comment from: Murtaza [Visitor] Email · http://Google.co.uk
    Murtaza Very good i never know about nameing of Sp is so important.will be carefull in future
    03/02/11 @ 07:41

    Leave a comment


    Your email address will not be revealed on this site.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)