I want to name one of my tables as ORDER
. Can I to use in SQL keywords as names? How bad is this practice? Whether to do so?
And if such situation already exists then how do I use name of this table in queries? For example, I want:
SELECT * FROM ORDER;
or
SELECT * FROM ORDER ORDER BY NAME;
wrap the tableName with backtick as
ORDER
is a reserved keyword.In my own opinion, using reserved keywords are fine except that you do not forget to handle it properly as it will give you such pain in the neck.
But through the years of designing schema, I never had used reserved keywords
:D
As observed in another answer, backticks are used in MySQL to indicate that a word is a database object, thus preventing confusion with reserved words - in other dialects of SQL, square brackets
[ ]
(SQLServer) or double quotes" "
(most other dialects) are used instead.In my experience, using reserved words in table structures tends to cause problems, especially when writing new queries - it can take a while to realise that the error being returned is due to a reserved word being a column name. There's also the point (as the existence of this question indicates) that not everyone knows that you can get around the problem by using the appropriate quoting characters in your query.