开发者

What do the `s around table/field names in SQL mean?

开发者 https://www.devze.com 2023-02-08 10:44 出处:网络
Here\'s an SQL statement that phpMyAdmin generated for me: SELECT * FROM `table_name` WHERE 1 You can see that table_name is surrounded by ` characters.

Here's an SQL statement that phpMyAdmin generated for me:

SELECT * FROM `table_name` WHERE 1

You can see that table_name is surrounded by ` characters.

Why?开发者_Go百科


It's used to enclose identifiers in MySQL.

It lets them have characters that would be ambiguous or otherwise invalid in normal 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


Its used as to escape/enclose characters, in case of a space or some other illegal character in the table or field name.

From the docs:

If an identifier contains special characters or is a reserved word, you must 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 at Section 8.3, “Reserved Words”.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号