Using the SQL keyword in a table or column header

I want to name one of my tables as ORDER . Can I use SQL keywords as names? How bad is this practice? Is there any need to do this?

And if such a situation already exists, then how can I use the name of this table in queries? For example, I want:

 SELECT * FROM ORDER; 

or

 SELECT * FROM ORDER ORDER BY NAME; 
+4
source share
2 answers

wrap the table name with the reverse, since ORDER is a reserved keyword.

 SELECT * FROM `ORDER` ORDER BY NAME; 

In my opinion, using reserved keywords is great, except that you remember to handle it properly, as this will give you such a pain in the neck.

But over the years of designing the circuit, I have never used the reserved keywords :D

+6
source

As another answer noted, backticks are used in MySQL to indicate that a word is a database object, which prevents confusion with reserved words - in other SQL dialects, square brackets [ ] (SQLServer) or double quotation marks " " (most other dialects) .

In my experience, the use of reserved words in table structures tends to cause problems, especially when writing new queries - it may take some time to understand that the error returned is due to the fact that the reserved word is the name of the column. It also indicates (as indicates the existence of this question) that not everyone knows that you can work around the problem by using the appropriate keywords in your request.

+5
source

All Articles