SQL Server Stored Procedure Naming Standards

Bobby P 231 Reputation points
2021-10-18T18:35:54.753+00:00

Just wondering what different standards may be out there for naming SQL Server Stored Procedures.

I don't mind CamelCase...But I'd personally prefer separating by underscore "_" or hyphens "-". To me it just makes it easier to read and decipher what the SQL Server Stored Procedure is used for.

I have read where you should use dashes or hyphens "-" as opposed to underscores "_" because certain elements do not handle underscores well.

So if someone can maybe give their two cents as to standards they've been exposed to and what they like and what they dislike about them, I'd GREATLY appreciate it.

Thanks in advance.

Developer technologies Transact-SQL
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Tom Phillips 17,771 Reputation points
    2021-10-18T20:46:04.913+00:00

    It is really up to you. I prefer CamelCase.

    I hate using underscores or hyphen. But I have not see it cause an issue in SQL Server, except in the case of databases with underscore or hyphen, don't do that, you will be sorry in the long run.

    0 comments No comments

  2. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2021-10-18T21:48:01.347+00:00

    If you use hyphens, procedure names needs to be quoted:

    CREATE PROCEDURE [my-very-own-procedure]
    

    since the hyphen is also the minus operator. You don't have to do this with underscores.

    As Tom says, it is up do you. I'm more used to using underscores, but currently I'm in a CamelShop. The only advice I can give is to be consistent.

    0 comments No comments

  3. Isabellaz-1451 3,616 Reputation points
    2021-10-19T02:50:58.497+00:00

    Hi @Bobby P

    If you prefer using underscores ,you can keep it .
    My advice to you is adding prefix to calrify what type the procedure is .
    Prefix :

    gen - General: CRUD, mostly
    rpt - Report: self-explanatory
    tsk - Task: usually something with procedural logic, run via scheduled jobs

    For example:

    genInsOrderHeader  
    genSelCustomerByCustomerID  
    genSelCustomersBySaleDate  
    genUpdCommentText  
    genDelOrderDetailLine  
    rptSelCustomersByState  
    rptSelPaymentsByYear  
    tskQueueAccountsForCollection  
    

    For more information,please refer to:https://stackoverflow.com/questions/238267/what-is-your-naming-convention-for-stored-procedures
    Best Regards,
    Isabella


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.