|
|
|
SSC-Dedicated
           
Group: Administrators
Last Login: Today @ 3:32 PM
Points: 31,419,
Visits: 13,732
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, June 17, 2009 8:45 AM
Points: 8,
Visits: 6
|
|
Great article, we follow the naming as per below. These cover some of the same but also more areas of SQL Server naming conventions. http://www.ssw.com.au/ssw/standards/DeveloperSQLServer/SQLServerStandard_1_ObjectNaming.aspx
http://www.ssw.com.au/ssw/standards/DeveloperSQLServer/SQLServerStandard_2_StoredProcedureNaming.aspx
http://www.ssw.com.au/ssw/standards/DeveloperSQLServer/SQLServerStandard_3_StoredProcedureFormatting.aspx
http://www.ssw.com.au/ssw/standards/DeveloperSQLServer/SQLServerStandard_4_IndexesNaming.aspx
Adam
|
|
|
|
|
SSCertifiable
       
Group: Moderators
Last Login: Thursday, May 09, 2013 12:38 PM
Points: 6,462,
Visits: 1,384
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 9:35 AM
Points: 2,749,
Visits: 1,407
|
|
Yes, good ideas here.
Anything that makes old code easy to read gets my vote.
Has anyone used sp_addextendedproperty to help comment objects within your databases?
LinkedIn Profile
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Sunday, November 25, 2012 3:50 PM
Points: 587,
Visits: 251
|
|
Steve, Agreed with everything you said. I'm particularly fond of commas preceeding column names.
Adam, Thanks for your guidelines.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, March 13, 2003 12:00 AM
Points: 1,
Visits: 1
|
|
Steve,
I totally agree with your comments and I personally use a style very similar to yours, and for the same reasons. We do not actually have a standard yet, but we're just in the process of looking at it now, so your article is timed perfectly.
|
|
|
|
|
SSC-Dedicated
           
Group: Administrators
Last Login: Today @ 3:32 PM
Points: 31,419,
Visits: 13,732
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, November 05, 2012 2:02 PM
Points: 164,
Visits: 84
|
|
I like the trick of putting the commas before the field name. Looked weird at first glance, but made perfect sense when explained. I will pass this article on to my co-developers; we already used Part 1 of the article to develop our naming standards.
David Poole asked about using sp_addextendedproperty to comment database objects. That is our standard for database documentation. I wrote an ASP app that allows the developer to select a database and view the extended properties for tables, columns, views, etc. Eventually, we want to extend the app to include an extended property for each system that uses a particular object. Our developers are more likely to document if it doesn't involve a word processor!
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, February 19, 2003 12:00 AM
Points: 14,
Visits: 1
|
|
Steve, thanks for the great article, it will create a lot of discussion. Here's my 2c worth.
All of these rules are GREAT if you use a text editor environment. But not so great if you use GUI. I personally always use GUI where possible. I am not able to understand a 50 line long SQL statement with joins on 10 tables without being able to see it graphically. Where these formatting ideas fall down in a GUI enviroment are: As soon as you view the code in A GUI enviromnent all your formatting disappears. Tabs don't appear the same way in text and GUI enviromnent so what looks great and all lined up in query analyzer is an undreadable mess in Access. You don't need aliases when you create a query in a GUI environment, because it fully qualifies the names for you automatically, and I personally find it harder to read aliases than fully qualified names. Basically the point is, unless your whole team now and in the future is going to use exclusively text editors, then you need to be flexible with a coding standard like this, because to re-format a large query created in a GUI enviroment just becuase the people who love to type can't read it, is a waste of time. The Answer? I beleive the answer lies in an automatic formatter - does anyone know of one? QUEST software has a fantastic tool for Oracle called Formatter Plus. I've asked them if they're doing one for SQL but they said not at this stage. Maybe if everyone can send them an email, they might get something happening.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Saturday, August 08, 2009 2:01 AM
Points: 33,
Visits: 6
|
|
If you have to be a ludite and use a text editor to develop SQL, rather than as suggested by another responder - use GUI it's easier - then it would also be advisable to make a distinction between table and column names and SQL RESERVED WORDS. The best way I have seen so far is :-
SELECT Column_Name_1 ,Column_Name_2 ,MAX(Column_Name_3) FROM tbl_Name WHERE Column_Name_1 > 0 AND Column_Name_2 > 0 .....etc..... GROUP BY Column_Name_1 ,Column_Name_2
Not sure how this will appear in the forum but it looks fine in a fixed spaced editor.
By using UPPERCASE for the reserved words it makes their importance stand out. and much easier to read.
|
|
|
|