Results 1 to 10 of 10

Thread: Stored Procedure Naming?

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Stored Procedure Naming?

    What techinques do you guys use when naming stored procedures?
    I like to go by function but it was brought up by an Architech that a sp we are working on should be appended by application name.

    We have over 3000 sp's here in just one database and by funciton really helps to find sp's for use in your app without having to accidentally rewrite a sp that already existed.

    Example 1:
    GetAllNotesForACustomerByCustomerKey

    Example 2:
    GetAllNotesForACustomerByCustomerKeyForApplicationXYZ

    And getting out of hand example: 3
    GetAllNotesAndActivityForACustomerByCustomerKeyBySortedNoteTypeAndDateRangeIfTheyHaveAnyNotesOrActiv ityAtAll

    I like to also append "usp_" before the name to help filter user created sp's from system.
    Example 1 is my preference.

    Even if example 2 is specific to a single app, there is no real realson to add an applications name to teh end IMO.

    Which do you guys do?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: Stored Procedure Naming?

    Recently we have started grouping things belonging to one application using the schema in SQL 2005. So we use what you have stated in example1 like, myAppName.GetDropDownValues.

    We have some databases that have been ported from 2000 and there we are stuck with a weird mix of naming conventions(some use old convention and a few applications have started using schema). The old convention that we follow is: pr_AppName_[Get/Set]_MySPDoesThis (I somehow like the pr_ over usp_ ) The only problematic thing that happens here is the SP name abbreviation. Each developer has their own choice of abbreviating and at times that becomes difficult for others to comprehend what that means.

  3. #3
    Hyperactive Member Max Peck's Avatar
    Join Date
    Oct 2007
    Posts
    384

    Re: Stored Procedure Naming?

    Quote Originally Posted by RobDog888 View Post
    [color=navy]What techinques do you guys use when naming stored procedures?

    ... snip ...

    And getting out of hand example: 3
    GetAllNotesAndActivityForACustomerByCustomerKeyBySortedNoteTypeAndDateRangeIfTheyHaveAnyNotesOrActiv ityAtAll
    That has happened in our shop.

    The technique I suggest you use is that you stop trying to make an application out of the database! We have had major performance problems to solve because some people (who are no longer with us) decided that stored procedures were the answer to EVERYTHING.

    Try the n-tier approach, it works.

    -Max
    The name's "Peck" .... "Max Peck"

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Stored Procedure Naming?

    3000 stored procedures.

    I usually consider how they would be sorted in most common places where they would be displayed like Management studio treeview/listview etc. This helps keep things neat & tidy as things related to one application etc. would all be displayed at one place rather than scattered.

    To do this I go from broad to specific. Like first usp.. then application name.. then procedure name etc.
    e.g.
    sql Code:
    1. usp_AppName_ProcName          -- User stored procedure specific to one application
    2. usp__ProcName            -- User stored procedure generic to more than one applications
    Last edited by Pradeep1210; Aug 29th, 2009 at 05:01 PM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Stored Procedure Naming?

    And getting out of hand example: 3
    GetAllNotesAndActivityForACustomerByCustomerKeyBySortedNoteTypeAndDateRangeIfTheyHaveAnyNotesOrActiv ityAtAll
    I would prefer to eleminate this option alltogether by passing appropriate parameters to the stored procedure like select criteria, sort field etc. Besides reducing the number of stored procedures in my database, it is also useful if we need to change something. We would need to change just one stored procedure as opposed to say 10 odd ones that return same/similar resultset with minor differences like select/sort fields etc.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Stored Procedure Naming?

    maybe something like this:
    sql Code:
    1. CREATE PROCEDURE usp_Customer_GetAllNotes
    2.     @CustomerId int = NULL,
    3.     @CustomerName int = NULL,
    4.     @SortField varchar(20) = NULL
    5. AS
    6. BEGIN
    7.     SELECT Customers.*
    8.     FROM Customers
    9.     WHERE (@CustomerId IS NULL OR  CustomerId = @CustomerId)
    10.       AND (@CustomerName IS NULL OR  CustomerName = @CustomerName)
    11.     ORDER BY CASE @SortField
    12.                 WHEN NULL THEN 1
    13.                 ELSE @SortField
    14.              END
    15. END
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Stored Procedure Naming?

    up_WhatItDoes

    Because the databases are shared across applications and they can also use the same SP. It'd be redundant to have two SPs with the same code in it.

  8. #8

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Stored Procedure Naming?

    Good feedback.

    Our main production sql database is 1TB is size and we have many databases and environments. Its a nightmare to maintain, glad its not me lol.

    Our apps all share most sp's and performance it the number #1 priority as we have maximium response times allowed under contract with our retailers and partners, some as little as 1 sec max, so to make the sp's all multi-use will degrade performance.

    But the run-on description naming of a sp is our problem. How descriptive should a sp be?
    Yes froggy a description is best but how detailed. Ours seem to most describe the function and the parameter(s) passed like "...ByCustomerKey" but if we have 5 different sp's all the same with different passed in parameters then there has to be some distinction between them.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Stored Procedure Naming?

    we use pr_[app code name]_[sub-system name]_[data]_[action]

    So it looks something like htis:
    pr_ERP_Customer_Details_Get <- for getting details of a customer
    or
    pr_ERP_Customers_Get <- for getting a list of customers
    shared sprocs are put in the "Library" system:
    pr_Library_Defaults_get

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Stored Procedure Naming?

    I personally disagree with putting the app name on because it represents a step away from code re-use. On that basis I'd go with naming them by function. We go with something like Customer_Get, Order_Set etc

    We use the same technique as Pradeep to eliminate the need for different sprocs for every possible search combination in our gets. I've yet to see it cause performance problems if all the possible parameter combinations can be handled by a single query's where clause. If, on the other hand, you find yourself branching the execution in a sproc using IF statements then you want to start considering creating a separate sprioc.

    Even eliminating the multi-parameter permutations, though, we do still have some really unwieldy names. The problem isn't so much in the parms the sproc recieves but in the fields it returns. The columns we want to display in one part of the system are different to the columns we want to display in another part. That gives us a choice of having one sproc that returns every possible column (very wasteful) or lots of sprocs that return specific column sets (massive code bloat and a need for run on names). In practice we end up doing something in the middle. I've yet to come up with a solution to that problem that I'm really happy with.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width