Using Language Keywords in SQL Statements
Well, i have on my database, a field call int, and i made a program on C# thats update 'int' and some开发者_如何学编程 other fields, all went good till the int field says error in syntax. and i want SQL to mean int as just a name of a field and not a keyword. Thanks you very much.
INT
is a reserved word. You can use reserved words in MySQL by enclosing them in back-ticks:
SELECT `int` FROM mytable ...
But it's honestly easier if you refrain from using reserved words as identifiers. That is, name your column something else when you define the table.
It's also recommended to name columns something that more clearly describes their content or purpose. int
is pretty over-generic and so it can be confusing; it's like naming a C# function thefunction()
. :-)
See http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords.html for lists of reserved words by version of MySQL.
Re your comment:
Be careful to use the correct type of quote symbols. Use single-quotes to delimit string and date literals. In MySQL, use back-ticks to delimit identifiers for columns, tables, etc.
SELECT ... WHERE `column` = 'string'
On a US keyboard, the back-ticks are on the same key with the tilde (~).
I apologize for assuming that you're using MySQL. You might be using Microsoft SQL Server or some other brand of RDBMS. Microsoft SQL Server doesn't use back-ticks; instead you need to enclose identifiers in square brackets.
See also Do different databases use different name quote?
精彩评论