sqlstored-proceduresnaming-conventions

What is your naming convention for stored procedures?


I have seen various rules for naming stored procedures.

Some people prefix the stored procedure name with usp_ (for user procedure), others with an abbreviation for the app name, and still others with an owner name. You shouldn't use sp_ in SQL Server unless you really mean it.

Some start the procedure name with a verb (Get, Add, Save, Remove). Others emphasize the entity name(s).

On a database with hundreds of stored procedures, it can be very hard to scroll around and find a suitable stored procedure when you think one already exists. Naming conventions can make locating a stored procedure easier.

Do you use a naming convention? Please describe it, and explain why you prefer it over other choices.


Solution

  • For my last project I used usp_[Action][Object][Process] so for example, usp_AddProduct or usp_GetProductList, usp_GetProductDetail. However now the database is at 700 procedures plus, it becomes a lot harder to find all procedures on a specific object. For example i now have to search 50 odd Add procedures for the Product add, and 50 odd for the Get etc.

    Because of this in my new application I'm planning on grouping procedure names by object, I'm also dropping the usp as I feel it is somewhat redundant, other than to tell me its a procedure, something I can deduct from the name of the procedure itself.

    The new format is as follows

    [App]_[Object]_[Action][Process]
    
    App_Tags_AddTag
    App_Tags_AddTagRelations
    App_Product_Add 
    App_Product_GetList
    App_Product_GetSingle
    

    It helps to group things for easier finding later, especially if there are a large amount of stored procedures.

    Regarding where more than one object is used, I find that most instances have a primary and secondary object, so the primary object is used in the normal instance, and the secondary is referred to in the process section, for example App_Product_AddAttribute.