Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
Naming Convention for UDF's, Views and SP's
30 posts, Page 1 of 3
1
2
3
»
»»
Naming Convention for UDF's, Views and SP's
Rate Topic
Display Mode
Topic Options
Author
Message
Andy Hyslop
Andy Hyslop
Posted Monday, February 11, 2013 4:11 AM
SSChasing Mays
Group: General Forum Members
Last Login: Today @ 9:28 AM
Points: 604,
Visits: 2,194
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
Grant Fritchey
Grant Fritchey
Posted Monday, February 11, 2013 5:08 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 9:14 AM
Points: 13,435,
Visits: 25,277
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 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #1418326
HowardW
HowardW
Posted Monday, February 11, 2013 5:24 AM
Ten Centuries
Group: General Forum Members
Last Login: Today @ 12:54 PM
Points: 1,082,
Visits: 7,893
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
Jeff Moden
Jeff Moden
Posted Monday, February 11, 2013 3:40 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 6:56 PM
Points: 33,107,
Visits: 27,026
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 "
R
ow-
B
y-
A
gonizing-
R
ow".
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."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1418668
Mike John
Mike John
Posted Monday, February 11, 2013 3:50 PM
SSCrazy
Group: General Forum Members
Last Login: Today @ 2:58 PM
Points: 2,645,
Visits: 4,641
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
Sean Lange
Sean Lange
Posted Monday, February 11, 2013 3:50 PM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 3:11 PM
Points: 8,938,
Visits: 8,512
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
Post #1418670
Jeff Moden
Jeff Moden
Posted Monday, February 11, 2013 4:03 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 6:56 PM
Points: 33,107,
Visits: 27,026
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 "
R
ow-
B
y-
A
gonizing-
R
ow".
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."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1418673
Chrissy321
Chrissy321
Posted Monday, February 11, 2013 4:03 PM
Mr or Mrs. 500
Group: General Forum Members
Last Login: Today @ 3:55 PM
Points: 567,
Visits: 3,059
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
Jeff Moden
Jeff Moden
Posted Monday, February 11, 2013 4:08 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 6:56 PM
Points: 33,107,
Visits: 27,026
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 "
R
ow-
B
y-
A
gonizing-
R
ow".
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."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1418678
Steven Willis
Steven Willis
Posted Monday, February 11, 2013 9:40 PM
SSC Veteran
Group: General Forum Members
Last Login: Today @ 7:16 PM
Points: 298,
Visits: 1,319
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 »
30 posts, Page 1 of 3
1
2
3
»
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.