Is there a fundamental difference between these statements
"select * from users where id = 1"
"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:
#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
No.
There is no difference. It's all about your habits.
It's like to ask is there any differences between these code blocks in C++:
int main() {
}
OR
int
main()
{
}
OR
int main()
{
}
Anyways the most common way to write SQL statements is to write keywords in UPPERCASE.
There is no fundamental difference between either of the above mentioned. However, the official SQL standards up until and including the latest, SQL:2008, have always used upper case to distinguish fields from operators.
精彩评论