What do table / field names mean in SQL?

Here is the SQL statement created for me by phpMyAdmin:

SELECT * FROM `table_name` WHERE 1 

You can see that table_name is surrounded by characters.

Why?

+4
source share
2 answers

He used to add identifiers in MySQL.

It allows them to have characters that are ambiguous or otherwise invalid in regular SQL, such as a space:

 `foo bar` - is a valid MySQL identifier foo bar - is not, since foo is the identifier, and bar is ambiguous 
+4
source

Used to output / close characters in case of a space or any other invalid character in the table or field name.

From the docs:

If the identifier contains special characters or a word is reserved, you should quote it whenever you refer to it. The set of alphanumeric characters from the current character set, "_" and "$" are not special. Reserved words are listed in Section 8.3, β€œReserved Words”.

http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

+3
source

Source: https://habr.com/ru/post/1338513/


All Articles