Is there a fundamental difference between these statements
"select * from users where id = 1"
OR
"SELECT* FROM users WHERE id = 1"
OR
'select * from users where id = 1'
OR
'SELECT * FROM users WHERE id = 1'
I was just wondering… I always used the 2nd method, but some collegues are bound to use other methods. What is the most common convention?
You have two separate issues:
Whether you use uppercase or lowercase for SQL keywords. This is a matter of taste. Documentation usually uses uppercase, but I suggest you just agree on either in the particular project.
How to quote SQL in your host language. Since strings are quoted with single quotes (
') in SQL, I suggest you use double quotes (") to quote SQL statements from your host language (or tripple quotes (""") if your host language is python). SQL does use double quotes, but only for names of tables, columns and functions that contain special characters, which you can usually avoid needing.In C/C++ there is a third option for quoting. If your compiler supports variadic macros (introduced in C99), you can define:
and use SQL like
SQL(SELECT * FROM users WHERE id = 1). The advantage is that this way the string can span multiple lines, while quoted strings must have each line quoted separately. The tripple quotes in python serve the same purpose.