Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

Naming Convention for UDF's, Views and SP's Expand / Collapse
Author
Message
Posted Monday, February 11, 2013 4:11 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: 2 days ago @ 7:14 AM
Points: 692, Visits: 2,815
I recently has to take a written SQL test for a client and one of the questions got me stumped (from memory was something like this):

Why should User Defined Functions not be prefixed UDF or udf, views not Prefixed with VW or vw and Stored Procedures not USP or usp

I couldn't come up with a reason for not using these naming conventions..

Can anyone enlighten me?

Andy


==========================================================================================================================
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe
Post #1418304
Posted Monday, February 11, 2013 5:08 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 8:22 AM
Points: 14,205, Visits: 28,534
They all can be. Makes things sloppy in my opinion. However, if you are dealing very large numbers of objects, for example, I saw this with stored procedures when we had over 1000 of them, and they all have the same first several letters, it actually can slow down performance of the underlying system as it tries to find the proc name. Now, this was back on 2000 and some hardware that wasn't terribly beefy, but it is possible.

Nah, the main reason I'd argue against that style notation is that it's VERY old school. Even most developers have tossed that object naming style for just using plain names for clarity.

Also, it's extremely inconsistent unless you also name all your tables tblXXX (and DO NOT, EVER, do that, ).

I just wouldn't because it reduces clarity and readability. Also, when I'm typing and anticipating my code completion to fill in the proc name or whatever, I know have to type about 6-8 characters instead of 3-5, slowing me down considerably.


----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server Query Performance Tuning
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1418326
Posted Monday, February 11, 2013 5:24 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, November 3, 2014 8:05 AM
Points: 1,191, Visits: 9,892
I do mostly agree with Grant and technically, all that data is available in the metadata and shouldn't need to be reflected in the object name.

However, I am quite fond of having some sort of naming convention for views, as it's not visible at a glance that you're referencing a view rather than a table and I find there are less developer mistakes when they're obviously marked in the name (e.g. re-utilising views inappropriately rather than going back to the base tables).
Post #1418337
Posted Monday, February 11, 2013 3:40 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 7:27 AM
Points: 35,769, Visits: 32,437
Andy Hyslop (2/11/2013)
I recently has to take a written SQL test for a client and one of the questions got me stumped (from memory was something like this):

Why should User Defined Functions not be prefixed UDF or udf, views not Prefixed with VW or vw and Stored Procedures not USP or usp

I couldn't come up with a reason for not using these naming conventions..

Can anyone enlighten me?

Andy


I agree with what has already been suggested but I have a cold, hard reason for not doing it for tables and views. There have been many times where I've needed to change the structue of a table but couldn't do so because of some bad coding practices on the front end. To trick the front end into not seeing the change, I changed the table name to something else and then made a view using the original table name. I don't know about you but it kind of defeats the whole purpose to have a view with a prefix of "tbl".


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1418668
Posted Monday, February 11, 2013 3:50 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, December 11, 2014 7:23 AM
Points: 2,668, Visits: 5,924
Just to reinforce what Jeff has said. I have also found views with a prefix of "tbl", I think for the same reasons - something started off as a table and the structure evolved over the years until it was changed to a view - so it may sound daft but it does happen.

So to me I would absolutely avoid:

tables with the prefix tbl
stored procs prefixed usp_ - it is just pointless letters
data types included in column names

Mike John



Post #1418669
Posted Monday, February 11, 2013 3:50 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:05 PM
Points: 13,327, Visits: 12,820
Jeff Moden (2/11/2013)
Andy Hyslop (2/11/2013)
I recently has to take a written SQL test for a client and one of the questions got me stumped (from memory was something like this):

Why should User Defined Functions not be prefixed UDF or udf, views not Prefixed with VW or vw and Stored Procedures not USP or usp

I couldn't come up with a reason for not using these naming conventions..

Can anyone enlighten me?

Andy


I agree with what has already been suggested but I have a cold, hard reason for not doing it for tables and views. There have been many times where I've needed to change the structue of a table but couldn't do so because of some bad coding practices on the front end. To trick the front end into not seeing the change, I changed the table name to something else and then made a view using the original table name. I don't know about you but it kind of defeats the whole purpose to have a view with a prefix of "tbl".


Synonyms could probably get around this type of scenario to Jeff. Then you don't need a view either. I do agree though that object prefixes are not a good idea.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1418670
Posted Monday, February 11, 2013 4:03 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 7:27 AM
Points: 35,769, Visits: 32,437
Synonyms won't work there. Remember, the structure of the table has been modified but the GUIs have to think it hasn't. This is especially true when you add a column but the app has some poorly formed embedded code that does INSERT/SELECTs without and insert column-list.

But, point taken. Why would anyone use Hungarian notation to name a synonym?


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1418673
Posted Monday, February 11, 2013 4:03 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: 2 days ago @ 11:01 AM
Points: 656, Visits: 3,960
I have never been a tbl-er but I have been a usp-er.

Lately I put everything in a schema. Is this a reasonable statement as far as a best practice? Always put all objects in a schema besides dbo.

Educational comments most welcome....
Post #1418674
Posted Monday, February 11, 2013 4:08 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 7:27 AM
Points: 35,769, Visits: 32,437
I put most everything in the DBO schema, Crissy. The only time I deviate from that is for utility and scratch objects. Of course, most of the work I do is at the batch level and what little I do for the front end can easily tolerate not using a bunch of schemas because I go for the next level of "security by separation" by keeping things in different databases.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1418678
Posted Monday, February 11, 2013 9:40 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Sunday, September 29, 2013 1:24 AM
Points: 429, Visits: 1,721
The databases I work on usually belong to clients and already have a schema. Often these instances are full of third-party objects with all kinds of naming conventions. So even though it does involve an extra bit of typing (isn't that what Red Gate SQL Prompt is for?), I use unique project-based prefixes so my objects will at least all be grouped together when I'm working in SSMS.

Also, though I'm starting to use scalar functions less and less, I still like to prefix them with "svf" or "tvf" so I know what output to expect. I'm not adverse to long descriptive names though...I think when it's a year or two later and I have to come back and look at something I hardly remember I'm always glad I used intelligible names. That includes variable names within procedures as well.

I waver back-and-forth inconsistently when naming columns base on datatype such as "intGender" vs "strGender" when it may not be obvious. Lately I tend to skip the camel casing and if it says EmployeeID then it's an integer and if EmployeeDesc then obviously it's a string. I have one current client who is bat-@#$% crazy about camel-casing EVERYTHING. So it's bitDog this, dtCat that, guidSession until it gets tiresome. He also thinks uniqueidentifiers are the best thing to use for primary keys on every table...oh, crap, now I'm ranting...don't get me started...

 
Post #1418740
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse