All Caps for SQL Syntax?

N4g4rok

Senior member
Sep 21, 2011
285
0
0
I'm curious, do you prefer tot type your SQL in all caps? Lately i've been correcting myself and doing so.
 

KLin

Lifer
Feb 29, 2000
30,208
558
126
I usually capitalize t-sql keywords (SELECT, FROM, WHERE, GROUP BY, HAVING) etc. etc. and use pascal casing for field names and table names.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
I'm with KLin, keywords get capitalized while the tables, columns, etc get case according to how they were created/inserted.
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
Agree with the above. Not that it really matters, but it is nice to be consistent throughout the codebase.
 

Dratickon

Junior Member
May 13, 2012
21
0
0
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.
 

KentState

Diamond Member
Oct 19, 2001
8,397
393
126
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.
 

N4g4rok

Senior member
Sep 21, 2011
285
0
0
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)
 );
 

KentState

Diamond Member
Oct 19, 2001
8,397
393
126
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.
 

AyashiKaibutsu

Diamond Member
Jan 24, 2004
9,306
4
81
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.
 

Snapshot1

Member
Dec 26, 2011
42
0
0
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
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
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.
 

Evadman

Administrator Emeritus<br>Elite Member
Feb 18, 2001
30,990
5
81
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.
 

pauldun170

Diamond Member
Sep 26, 2011
9,318
5,399
136
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.
 

Evadman

Administrator Emeritus<br>Elite Member
Feb 18, 2001
30,990
5
81
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.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
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?
 

Evadman

Administrator Emeritus<br>Elite Member
Feb 18, 2001
30,990
5
81
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.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |