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 12345»»»

Coding Standards Part 2 - Formatting Expand / Collapse
Author
Message
Posted Sunday, June 30, 2002 12:00 AM


SSC-Dedicated

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

Group: Administrators
Last Login: Yesterday @ 2:28 PM
Points: 33,062, Visits: 15,174
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/sjones/codingstandardspart2formatting.asp






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #5154
Posted Sunday, June 30, 2002 6:09 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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




Post #36599
Posted Sunday, June 30, 2002 9:00 PM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: Moderators
Last Login: Yesterday @ 7:55 AM
Points: 6,779, Visits: 1,858
Good article. In particular the point about putting spaces in so that you can jump from word to word easily is one often overlooked.

Andy
http://www.sqlservercentral.com/columnists/awarren/




Andy
SQLAndy - My Blog!
Connect with me on LinkedIn
Follow me on Twitter
Post #36600
Posted Monday, July 1, 2002 1:45 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 3:50 PM
Points: 2,890, Visits: 1,780
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
Newbie on www.simple-talk.com
Post #36601
Posted Monday, July 1, 2002 5:36 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Monday, March 24, 2014 11:20 PM
Points: 587, Visits: 260
Steve, Agreed with everything you said. I'm particularly fond of commas preceeding column names.

Adam, Thanks for your guidelines.




Post #36602
Posted Monday, July 1, 2002 8:35 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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.




Post #36603
Posted Monday, July 1, 2002 8:54 AM


SSC-Dedicated

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

Group: Administrators
Last Login: Yesterday @ 2:28 PM
Points: 33,062, Visits: 15,174
Thanks for all the comments. This is something that I have found helpful as well and hopefully others will adopt something similar to standardize their environments.

Steve Jones
sjones@sqlservercentral.com
http://www.sqlservercentral.com/columnists/sjones







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #36604
Posted Monday, July 1, 2002 11:46 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, November 5, 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!



Post #36605
Posted Monday, July 1, 2002 5:35 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

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.




Post #36606
Posted Tuesday, July 2, 2002 12:31 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, August 8, 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.




Post #36607
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse