|
|
|
View Poll Results: All Caps for SQL Syntax?
|
|
Yes
|
  
|
19 |
48.72% |
|
No
|
  
|
5 |
12.82% |
|
A mix of both
|
  
|
15 |
38.46% |
 |
12-01-2012, 10:08 PM
|
#1
|
|
Senior Member
Join Date: Sep 2011
Location: Northwest Arkansas, USA
Posts: 276
|
All Caps for SQL Syntax?
I'm curious, do you prefer tot type your SQL in all caps? Lately i've been correcting myself and doing so.
__________________
Primary: Hades
> AMD Phenom II X4 970 @ 3.9 Ghz + Antec Kuhler 620
> ASUS M4A79XTD EVO
> XFX Radeon R7950 Black Edition
> 128GB Samsung 830 SSD + 2TB Hitachi Deskstar HDD
> 8GB G.SKILL Ripjaws DDR3 RAM @ 1600 Mhz
> NZXT Hades Case
Home Server: Charon
> AMD Sempron 145 @ 2.8 Ghz + Stock cooler
> GigaByte GA-M68MT-S2
> 2TB Seagate Barracuda Green HDD + 2TB Samsung Spinpoint HDD
> 4GB Crucial DDR3 RAM @ 1333
> NZXT Hush Case
|
|
|
12-02-2012, 10:42 AM
|
#2
|
|
Lifer
Join Date: Feb 2000
Location: Phreaznaux
Posts: 28,145
|
I usually capitalize t-sql keywords (SELECT, FROM, WHERE, GROUP BY, HAVING) etc. etc. and use pascal casing for field names and table names.
__________________
'L_'
|
|
|
12-02-2012, 10:44 AM
|
#3
|
|
Elite Member
Join Date: Sep 2001
Posts: 30,636
|
I'm with KLin, keywords get capitalized while the tables, columns, etc get case according to how they were created/inserted.
|
|
|
12-02-2012, 11:33 AM
|
#4
|
|
Moderator Programming
Join Date: Sep 2005
Posts: 8,144
|
Quote:
Originally Posted by KLin
I usually capitalize t-sql keywords (SELECT, FROM, WHERE, GROUP BY, HAVING) etc. etc. and use pascal casing for field names and table names.
|
This.
|
|
|
12-02-2012, 02:30 PM
|
#5
|
|
Lifer
Join Date: Jul 2004
Location: Austin, TX
Posts: 20,207
|
Agree with the above. Not that it really matters, but it is nice to be consistent throughout the codebase.
|
|
|
12-02-2012, 06:02 PM
|
#6
|
|
Junior Member
Join Date: May 2012
Posts: 21
|
Quote:
Originally Posted by KLin
I usually capitalize t-sql keywords (SELECT, FROM, WHERE, GROUP BY, HAVING) etc. etc. and use pascal casing for field names and table names.
|
This is also what I tend to do. I work with a lot of legacy code/queries that were written without any standardized coding style, so I've learned that the little things like this make a difference and add up over time.
|
|
|
12-03-2012, 11:10 PM
|
#7
|
|
Lifer
Join Date: Feb 2003
Posts: 20,480
|
Quote:
Originally Posted by KLin
I usually capitalize t-sql keywords (SELECT, FROM, WHERE, GROUP BY, HAVING) etc. etc. and use pascal casing for field names and table names.
|
++
|
|
|
12-04-2012, 04:32 PM
|
#8
|
|
Diamond Member
Join Date: Oct 2001
Location: Atlanta, GA
Posts: 4,391
|
Capitalization is fine, but the biggest pet peeve is indents for me. A block of SQL code that I have to reformat to read is not pleasant. However, reserved T-SQL syntax is always in caps for me and objects match how the meta data.
|
|
|
12-04-2012, 06:32 PM
|
#9
|
|
Senior Member
Join Date: Sep 2011
Location: Northwest Arkansas, USA
Posts: 276
|
Quote:
Originally Posted by KentState
the biggest pet peeve is indents for me.
|
What kind of indentation would you like to see in SQL code? I usually try to fit everything into C/C++ like blocks if i can. For example:
Code:
CREATE TABLE Persons
(
P_Id int primary key,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
__________________
Primary: Hades
> AMD Phenom II X4 970 @ 3.9 Ghz + Antec Kuhler 620
> ASUS M4A79XTD EVO
> XFX Radeon R7950 Black Edition
> 128GB Samsung 830 SSD + 2TB Hitachi Deskstar HDD
> 8GB G.SKILL Ripjaws DDR3 RAM @ 1600 Mhz
> NZXT Hades Case
Home Server: Charon
> AMD Sempron 145 @ 2.8 Ghz + Stock cooler
> GigaByte GA-M68MT-S2
> 2TB Seagate Barracuda Green HDD + 2TB Samsung Spinpoint HDD
> 4GB Crucial DDR3 RAM @ 1333
> NZXT Hush Case
|
|
|
12-04-2012, 07:26 PM
|
#10
|
|
Diamond Member
Join Date: Oct 2001
Location: Atlanta, GA
Posts: 4,391
|
I hate seeing something like:
Code:
WITH cte (column1, column2)
AS (SELECT COLUMN1, COLUMN2 FROM TABLE)
SELECT
COLUMN1, COLUMN2,
COLUMN3, COLUMN4....
FROM A INNER JOIN B ON A. = B.
INNER JOIN C ON B. = C. INNER JOIN D ON
A. = D. INNER JOIN cte ON ....
WHERE A.VALUE > B.VALUE AND (D.VALUE = '' OR C.VALUE = '')
AND C.VALUE = ''
GROUP BY COLUMN1, COLUMN2,
COLUMN3, COLUMN4....
I much prefer:
Code:
WITH cte (column1, column2)
AS
(
SELECT COLUMN1, COLUMN2
FROM TABLE
)
SELECT
COLUMN1,
COLUMN2,
COLUMN3,
COLUMN4....
FROM A
INNER JOIN B ON
A. = B.
INNER JOIN C ON
B. = C.
INNER JOIN D ON
A. = D.
INNER JOIN cte ON.....
WHERE A.VALUE > B.VALUE
AND (D.VALUE = '' OR C.VALUE = '')
AND C.VALUE = ''
GROUP BY
COLUMN1,
COLUMN2,
COLUMN3,
COLUMN4....
Just break it apart enough so I can read it. I've seen various indentation methods and as long as it's used consistently, I'm happy. There are some SQL beautifier tools that do a great job right in Management Studio.
|
|
|
12-04-2012, 08:07 PM
|
#11
|
|
Diamond Member
Join Date: Jan 2004
Location: Maryland
Posts: 8,045
|
Last office capped sql key words. This office we cap variables... At the end of the day, I don't really care I just write it to fit in with the code that's there, but I do like key words a little better.
__________________
The large print giveths and the small print taketh away.
|
|
|
12-04-2012, 10:38 PM
|
#12
|
|
Senior Member
Join Date: Mar 2012
Location: USA left coast
Posts: 447
|
there's a formatting tool here that some may find useful
Instant SQL Formatter
|
|
|
12-10-2012, 11:57 AM
|
#13
|
|
Member
Join Date: Dec 2011
Location: Burlington, Ontario, Canada
Posts: 37
|
If maintaining existing code I will try to conform to whatever convention is established.
In new code I tend to avoid capitalization but I am generally using SQL Server Management Studio which color-codes keywords, comments, etc. so they are easy to distinguish WITHOUT CAPITALIZATION which many of us have come to associate with shouting.
But careful / consistent indentation and suitable comments are both mandatory, and I apply these to both new and existing work without exception.
Snapshot1
__________________
i7-2600 · ASUS P8Z68-PRO/GEN3 · Corsair Vengeance LP 16GB DDR3 1600 · Radeon HD 6870 1GB · Corsair Force 3 120GB SSD · WD Caviar Green 2TB HDD · Corsair Obsidian 650D · Seasonic X-760 · Corsair 650D · Enermax ETD-T60-TB · Windows 7 Ultimate 64 bit SP1 · Dell U2770
|
|
|
12-10-2012, 12:12 PM
|
#14
|
|
Moderator Programming
Join Date: Sep 2005
Posts: 8,144
|
I think the point is that, in case-insensitive syntaxes, if you don't adhere to a convention you end up with a mix of styles. When I started learning SQL using dblib the convention that MS inherited from Sybase was uppercase for reserved words. So I've stuck with that over the years.
|
|
|
12-12-2012, 09:26 PM
|
#15
|
|
Senior Member
Join Date: Jul 2004
Posts: 739
|
Quote:
Originally Posted by KLin
I usually capitalize t-sql keywords (SELECT, FROM, WHERE, GROUP BY, HAVING) etc. etc. and use pascal casing for field names and table names.
|
Same here
|
|
|
12-17-2012, 10:11 AM
|
#16
|
|
Administrator Emeritus Elite Member
Join Date: Feb 2001
Posts: 30,888
|
Quote:
Originally Posted by KLin
I usually capitalize t-sql keywords (SELECT, FROM, WHERE, GROUP BY, HAVING) etc. etc. and use pascal casing for field names and table names.
|
This, and it is what I teach everyone else that I work with.
__________________
Dan (Schmin) 1981-2003. Rest in Peace
I want to drinkify all my snacks. Chewing is for people living in the 19th century.
My Blog
|
|
|
12-18-2012, 10:51 AM
|
#17
|
|
Golden Member
Join Date: Sep 2011
Posts: 1,391
|
We are an all caps shop here.
With rent-a-devs floating in and out the easiest and quickest way to enforce a convention is just make everything all caps when it comes to queries.
It is more than just readability\making the resident coder nazi's happy.
The performance boost from shared statements directly impacts application performance at least for repeated simple queries.
SELECT BITCHES FROM UP_IN_HERE WHERE UPPER(BOOTY) = 'BOUNCING'
is not the same as
SELECT Bitches FROM Up_in_here WHERE upper(BOOTY) = 'BOUNCING'
is not the same as
select bitches from up_in_here where upper(booty) = 'BOUNCING'
If there are lot of queries looking for bouncing booty...we don't want the RDBMS to have to go through every little song and dance routine to fetch the data again and again.
After years and years of having mixed skill sets\experience floating through the shop, we've found that one of the ways to ensure consistency and reduce headaches at least when it comes to sql is to hand them the naming convention cheat sheet and to rock the caps lock.
There are always times where folks will check in a script\code with the convention they are used to but since its easy to spot we are pretty quick to identify the perp (who obviously doesn't listen or read the mandatory toilet reading when joining the department), implement a public shaming and place the code under public scrutiny.
HOWEVER, this doesn't apply to all of our scripts (procedures\functions etc etc where typical coding conventions are used).
In summary
1. All my SQL queries are shouted (caps lock rocked)
2. Strict naming convention policies.
3. Rules of the shop trump whatever standard your used to or comfortable with.
|
|
|
01-04-2013, 11:00 PM
|
#18
|
|
Administrator Emeritus Elite Member
Join Date: Feb 2001
Posts: 30,888
|
Quote:
Originally Posted by pauldun170
SELECT BITCHES FROM UP_IN_HERE WHERE UPPER(BOOTY) = 'BOUNCING'
1. All my SQL queries are shouted (caps lock rocked)
|
That is hard as hell to read. I wonder how much time is spent debugging vs using mixed case.
__________________
Dan (Schmin) 1981-2003. Rest in Peace
I want to drinkify all my snacks. Chewing is for people living in the 19th century.
My Blog
|
|
|
01-05-2013, 01:29 AM
|
#19
|
|
Moderator Programming
Join Date: Sep 2005
Posts: 8,144
|
Quote:
Originally Posted by pauldun170
SELECT BITCHES FROM UP_IN_HERE WHERE UPPER(BOOTY) = 'BOUNCING'
is not the same as
SELECT Bitches FROM Up_in_here WHERE upper(BOOTY) = 'BOUNCING'
is not the same as
select bitches from up_in_here where upper(booty) = 'BOUNCING'
|
I thought SQL was case insensitive. You're saying the engine treats those as different queries?
|
|
|
01-05-2013, 03:41 AM
|
#20
|
|
Golden Member
Join Date: Jun 2009
Posts: 1,552
|
Quote:
Originally Posted by Markbnj
I thought SQL was case insensitive. You're saying the engine treats those as different queries?
|
maybe MySQL does but it also does a lot of other weird things. /bashing
I also have never heard of this...
|
|
|
01-07-2013, 02:10 PM
|
#21
|
|
Administrator Emeritus Elite Member
Join Date: Feb 2001
Posts: 30,888
|
Quote:
Originally Posted by beginner99
maybe MySQL does but it also does a lot of other weird things. /bashing
I also have never heard of this...
|
If installed on a windows system, MySQL table names and databases are not case sensitive. If installed on some flavor of *ix, it IS case sensitive, and goes by the underlying OS rules. A database corresponds to a folder in the OS, and a table corresponds to a file. *ix OS's are case sensitive for folders and files, so that means MySQL is too on those OS's. Same thing with table aliases, and other things.
I can think of nothing to call this behavior besides absolutely retarded.
__________________
Dan (Schmin) 1981-2003. Rest in Peace
I want to drinkify all my snacks. Chewing is for people living in the 19th century.
My Blog
|
|
|
01-07-2013, 02:55 PM
|
#22
|
|
Golden Member
Join Date: Oct 2007
Location: CHICAGO (South Loop)
Posts: 1,950
|
Usually a mix, but if I use one or the other, I use all lowercase.
__________________
Intel C2Q 9450@3ghz | Intel X25-M G2 160GB | MSI Radeon 5870 (on latest WHQL)
Ubuntu 12.04LTS + Win7Pro64 | 8GB Mushkin XP2-6400 (4-4-4-12) | Lian Li PC-A05NB
Asus P5Q-E (P45 / ICH10R) | Corsair HX650 | Asus U3S6 | Asus VS278Q-P + Dell 2005FPW
+ Samsung PN50B650 | External Seagate GoFlex 1.5TB USB 3.0 + External LiteOn IHES208 BR
________________
Linus on Nvidia
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:35 PM.
|