patternsqlCritical
Benefits of using backtick (`) in MySQL queries?
Viewed 0 times
mysqlbacktickbenefitsusingqueries
Problem
In MySQL we can create queries with or without the backtick (``
) symbol. Example:
SELECT * FROM TEST;
SELECT * FROM TEST;
Both works fine in mysql-console.
Is there any technical difference between them?
Is there any benefit using (``) over over simple queries?Solution
They are called quoted identifiers and they tell the parser to handle the text between them as a literal string. They are useful for when you have a column or table that contains a keyword or space. For instance the following would not work:
But the following would:
Also, the following would get an error, because
But the following would be parsed correctly:
I hope this helps you.
CREATE TABLE my table (id INT);But the following would:
CREATE TABLE `my table` (id INT);Also, the following would get an error, because
COUNT is a reserved keyword:SELECT count FROM some_tableBut the following would be parsed correctly:
SELECT `count` FROM some_tableI hope this helps you.
Code Snippets
CREATE TABLE my table (id INT);CREATE TABLE `my table` (id INT);SELECT count FROM some_tableSELECT `count` FROM some_tableContext
StackExchange Database Administrators Q#23129, answer score: 50
Revisions (0)
No revisions yet.