July 8, 2015 at 7:31 am
Hi,
Please can anyone point me to any conventions for using ID or Id in column names, e.g. TableColumnID and TableColumnId in T-SQL?
There is a debate in programming circles about this and microsoft publish guidance for .NET (https://msdn.microsoft.com/en-us/library/ms229043.aspx). However, I was hoping to find some documented convention for T-SQL.
Thanks
July 8, 2015 at 7:48 am
John Corkett (7/8/2015)
Hi,Please can anyone point me to any conventions for using ID or Id as column names in T-SQL?
There is a debate in programming circles about this and microsoft publish guidance for .NET (https://msdn.microsoft.com/en-us/library/ms229043.aspx). However, I was hoping to find some documented convention for T-SQL.
Thanks
There is no right or wrong answer to this. And AFAIK there is no documented convention for any naming conventions across the board. I prefer "ID" because depending on the font, "Id" can be confused with "ld". Just look at the title of this thread to see a good example. π As with everything when it comes to naming conventions, the most important thing is to be consistent. There is my 2Β’.
_______________________________________________________________
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 β Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 8, 2015 at 7:50 am
If the name of the column is simply "ID", regardless of case, that's probably not a good practice.
It means nothing. Would table_name_ID make more sense?
As for naming conventions in a DB, you will get as many opinions as there are molecules of air!
Come up with a convention that works for your organization, and stick to it
I tend to stick to English words and avoid abbreviations or acronyms.
I personally dislike both PascalCase and camelCase. To me, either of these are difficult to read. I normally use underscores.
THisIsMyTableName
thisIsMyTableName
This_Is_My_Table_Name
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
July 8, 2015 at 8:02 am
I was remiss in mentioning as Michael did that if the entire name is "ID" or "Id" then neither is appropriate. That kind of thing means you have to change the name of that column to give it meaning when it is a foreign key. Column names changing between tables is a huge pet peeve of mine as it is incredibly confusing to work with.
_______________________________________________________________
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 β Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 8, 2015 at 8:14 am
Where I work "ID" was used everywhere if it was the primary key. Then foreign keys would become AccountID for example. Programmers claimed it was easier for them to tell if the ID's "belonged" to that table or another one (TableName + ID).
That being said I completely disagree and I am slowly convincing them to change the convention here on new projects. π
July 8, 2015 at 8:23 am
We've got a database that has all the primary keys as ID and all foreign keys as Table+ID and it's horrible to work with. There's two closely related tables that both have SiteID columns in but both are different values. Nine times out of ten, if there's a problem with a report it's because those two columns have been joined directly.
With regards to cases, we use PascalCase because SSRS will automatically put the spaces in at the capitals. I actually prefer to use underscores but I don't mind not because I can see the benefits of PascalCase.
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
July 8, 2015 at 8:32 am
Sean Lange (7/8/2015)
John Corkett (7/8/2015)
Hi,Please can anyone point me to any conventions for using ID or Id as column names in T-SQL?
There is a debate in programming circles about this and microsoft publish guidance for .NET (https://msdn.microsoft.com/en-us/library/ms229043.aspx). However, I was hoping to find some documented convention for T-SQL.
Thanks
There is no right or wrong answer to this. And AFAIK there is no documented convention for any naming conventions across the board. I prefer "ID" because depending on the font, "Id" can be confused with "ld". Just look at the title of this thread to see a good example. π As with everything when it comes to naming conventions, the most important thing is to be consistent. There is my 2Β’.
Agreed - no right or wrong answer unless the documented naming convention for your database says one thing and you don't follow the specified naming convention.
If there is no naming convention specified, then create one and follow it.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
July 8, 2015 at 10:21 am
yb751 (7/8/2015)
Where I work "ID" was used everywhere if it was the primary key. Then foreign keys would become AccountID for example. Programmers claimed it was easier for them to tell if the ID's "belonged" to that table or another one (TableName + ID).That being said I completely disagree and I am slowly convincing them to change the convention here on new projects. π
Heh... that being said, beware the page-split if you make such changes. "Here there be dragons".
--Jeff Moden
Change is inevitable... Change for the better is not.
July 8, 2015 at 12:04 pm
Jeff Moden (7/8/2015)
yb751 (7/8/2015)
Where I work "ID" was used everywhere if it was the primary key. Then foreign keys would become AccountID for example. Programmers claimed it was easier for them to tell if the ID's "belonged" to that table or another one (TableName + ID).That being said I completely disagree and I am slowly convincing them to change the convention here on new projects. π
Heh... that being said, beware the page-split if you make such changes. "Here there be dragons".
Yeah, I'm not making changes to any existing DB's. π
July 10, 2015 at 2:49 am
It doesn't matter a lick.
I'd just strongly argue for consistency to help promote clarity.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply