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?
Whenever you want some text data from your SQL database to be displayed in lowercase, use the LOWER() function. This function takes as an argument a string or the name of a column whose text values are to be displayed in lowercase.
The SQL keywords (SELECT, FROM, WHERE, etc.) are case-insensitive, yet they are frequently expressed in all capitals. Table and column names are case-sensitive in some settings. MySQL provides a setting that allows you to enable or disable it.
The Proper Case processor converts text attribute values to upper case for the first character of each word and to lower case for subsequent characters in the word.
Table names are stored in lowercase on disk and name comparisons are not case-sensitive. MySQL converts all table names to lowercase on storage and lookup. This behavior also applies to database names and table aliases.
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:
#define SQL(...) #__VA_ARGS__
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.
There is no difference in terms of how it will work, but usually I put SQL keywords in uppercase so it would be:
SELECT * FROM users WHERE id = 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With