Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Naming Convention for UDF's, Views and SP's


Naming Convention for UDF's, Views and SP's

Author
Message
Andy Hyslop
Andy Hyslop
Say Hey Kid
Say Hey Kid (706 reputation)Say Hey Kid (706 reputation)Say Hey Kid (706 reputation)Say Hey Kid (706 reputation)Say Hey Kid (706 reputation)Say Hey Kid (706 reputation)Say Hey Kid (706 reputation)Say Hey Kid (706 reputation)

Group: General Forum Members
Points: 706 Visits: 3022
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..Crazy

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
Grant Fritchey
Grant Fritchey
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17527 Visits: 32252
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, :w00tSmile.

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
HowardW
HowardW
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1211 Visits: 9892
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).
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44831 Visits: 39849
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..Crazy

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.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is usually not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Mike John
Mike John
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2672 Visits: 5958
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



Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16523 Visits: 16990
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..Crazy

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. :-P 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)
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44831 Visits: 39849
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? :-P

--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.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is usually not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Chrissy321
Chrissy321
Say Hey Kid
Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)

Group: General Forum Members
Points: 668 Visits: 4571
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....
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44831 Visits: 39849
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.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is usually not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Steven Willis
Steven Willis
SSC-Addicted
SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)

Group: General Forum Members
Points: 477 Visits: 1721
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...:-P

 
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search