Usage of backtick (`) in SQL
Although the backtick (`) is widely used, it has no special meaning in the SQL standard.
Identifier reference
The SQL standard requires the use of double quotes to quote identifiers:
SELECT "select" FROM "from" WHERE "where" = "group by";
MySQL Usage
In MySQL, backticks can be used as an alternative to double quotes to quote identifiers:
SELECT `select` FROM `from` WHERE `where` = `group by`;
Other databases
Various databases handle identifier references differently:
[]
When to quote identifiers
Normally, identifiers should not be quoted unless absolutely necessary. Some common scenarios that require citation include:
Quotation usage of values and field names
Values must always be enclosed in single quotes:
SELECT * FROM table WHERE field = 'value';
Field names can be enclosed in double or single quotes, but this is not mandatory:
SELECT "field" OR field FROM table;
The above is the detailed content of When and How Should I Use Backticks in SQL?. For more information, please follow other related articles on the PHP Chinese website!