February 27, 2009 at 10:50 am
Jeff Moden (2/26/2009)
I follow the following casing standard...All SQL Keywords in UPPER CASE.
All database names, table names, procedure names, column names, column aliases, variable names (basically, my stuff) etc, in MixedCase with no underscores. The exception to the rule of no underscores is for triggers, indexes, constraints, and references (FK's).
Table aliases and owner/schema in all lower case. Normaly kept to 5 characters or less, there's no need for underscores. Here's an example (Tally table)...
String literals as required.
Looks pretty good even in a monochromatic environment like below...
CREATE PROCEDURE dbo.TallyTableRebuild AS
/**********************************************************************************************************************
Purpose:
This stored procedure conditionally drops and rebuilds the dbo.Tally table.
Revision History:
Rev 0 - 10 Feb 2009 - Jeff Moden - Initial Creation and unit test.
- FogBugz Case xxxx - Create/manage working environment for projectnamehere.
Fogbugz, cool...
Just one thing tho, data types a keyword, hmm...
Max
February 27, 2009 at 10:53 am
Bob Hovious (2/26/2009)
Sheep without a shepherd are prone to wander....
right nutter, Bob... :rolleyes:
Max
February 27, 2009 at 11:26 am
Chris Morris (2/27/2009)
Jeff Moden (2/27/2009)
Oracle... when code is autogenned, it comes out in all uppercase for things like column names whether you want it to or not. Oracle peeps have gotten into the habit of using underscores to make things readable in autogenned code. Problem there is, they only have 30 characters per object name to boot... so they also end up having to follow an abbreviation standard instead of using whole words like "Date" (DT).Heh tell me about it - I'm currently writing interface code between PS and an SQL2k db. The Oracle peeps throw UPPER_CASE AND UNDR_SCRD ABBRVD stuff WITHNOWHITESPACE at me all the time, and they don't understand simple stuff like UPDATE...FROM... which we take for granted. It's driving me bonkers!
hmm, Oracle... perpetual afterbirth that RDBMS is. It seems it just didn't move on from mainframe. I'm pretty much with Jeff and Gail but column aliases could be something along the lines of:
SELECT [First Name] = c.FirstName, -- note space after comma
Surname = c.LastName,
FROM t_Customers c -- ideally two tabs to cater for longer joins and aligning with GROUP BY clause (I know there's default formatting differences btw analyzer and SSMS though)
Always wondered of there was an overhead with using equal aliases though. Does anyone put their aliases in inverted commas?
As you can see I don't have an isssue with using underscores in my object names as this is an universal character. Tried to get td_ for data (fact) tables and tl_ for lookup (dimension) adopted, but no one seems to want to play.
Lesnynk-Ruddick bring back any memories (anyone remember what that the proper spelling for that was, it was based on hungarian).
Max
February 27, 2009 at 12:23 pm
Max (2/27/2009)
Always wondered of there was an overhead with using equal aliases though.
No, but it is deprecated syntax
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
February 27, 2009 at 1:12 pm
Here's one of my favorite type of problem:
http://www.sqlservercentral.com/Forums/Topic665812-266-1.aspx
At least they have backups.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
February 27, 2009 at 1:17 pm
Jack Corbett (2/27/2009)
Here's one of my favorite type of problem:http://www.sqlservercentral.com/Forums/Topic665812-266-1.aspx
At least they have backups.
They know how to do backups, but not how to restore them. They also think you can't back up the system databases....
I'm still shocked by things like that. Why bother figuring out how to back stuff up if you don't also figure out what the backups are actually FOR?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
February 27, 2009 at 1:18 pm
Atleast they did not make the cardinal sin of no back ups. He is a developer. Still had sense to back up the DB while there are DBAs out there who do not do regular back ups.
-Roy
February 27, 2009 at 1:26 pm
Roy Ernest (2/27/2009)
Atleast they did not make the cardinal sin of no back ups. He is a developer. Still had sense to back up the DB while there are DBAs out there who do not do regular back ups.
True, but at the same time, the question seems to me like it should have been: "A database was lost. We have backups. We don't know how to get it back from the backups, but they do exist. How do we restore from backups?" As opposed to, "Mistakenly deleted database data and log files. Can the files be recreated, how can we restore the data and log files very urgent "
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
February 27, 2009 at 1:39 pm
I agree on that part with you. 🙂 Question was phrased wrong and you had to ask them to find out what back ups they had.
-Roy
February 27, 2009 at 1:44 pm
Today is the first day that I noticed that there are two GSquared's.... 🙂
GSquared original and a G raised to 2. Both answered on the same thread....:hehe:
-Roy
February 27, 2009 at 1:44 pm
I'm guessing we haven't seen the last of this.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
February 27, 2009 at 2:21 pm
Roy Ernest (2/27/2009)
Today is the first day that I noticed that there are two GSquared's.... 🙂GSquared original and a G raised to 2. Both answered on the same thread....:hehe:
There is ONLY one GSquared - the other is an "wannabee"! 😉
-- You can't be late until you show up.
February 27, 2009 at 4:22 pm
GilaMonster (2/27/2009)
Max (2/27/2009)
Always wondered of there was an overhead with using equal aliases though.No, but it is deprecated syntax
Pity, it's grown on me and quite like it, somehow it's quite readable. Always used AS
which is a whole extra character.
Max
February 27, 2009 at 5:31 pm
Max (2/27/2009)
GilaMonster (2/27/2009)
Max (2/27/2009)
Always wondered of there was an overhead with using equal aliases though.No, but it is deprecated syntax
Pity, it's grown on me and quite like it, somehow it's quite readable. Always used
AS
which is a whole extra character.
I really, really like the ...
SELECT alias = ColumnOrExpression
... syntax because of two things... 1st, it makes it really easy to write test code for an update... when you're done, just change the SELECT to a SET and and the UPDATE above that.
2nd, since "expression" can vary widely in length, the use of "AS" ends up as pretty much a ragged right adventure in trying to find column aliases. When the column aliases to the left and the fact that they're pretty much all the same length in a query, it makes readability a whole lot easier.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 27, 2009 at 5:34 pm
GilaMonster (2/27/2009)
Jeff Moden (2/26/2009)
[Great minds think alike... 😛 modeled very close to what the query designers in 2k and 2k5 spit out... makes it easier for "coders" to comply.Not that i ever use those query designers.
Main difference from yours is that I sometimes use mixed case for aliases (especially column aliases), and I'll honour the case of the system objects. So master.dbo.sysobjects
Yep... Like I said, I use mixed case for column aliases, as well. Seems like the only difference between you and me as that I never honor the case of the system objects except for very large auto-generated scripts... even then, if it's going to become production code, I'll go in and clean it all up to match my conventions.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 15 posts - 2,101 through 2,115 (of 66,738 total)
You must be logged in to reply to this topic. Login to reply