Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In MySQL we can create queries with or without the backtick (`) symbol. Example:

  1. SELECT * FROM TEST;
  2. 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?

share|improve this question
up vote 19 down vote accepted

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:

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_table

But the following would be parsed correctly:

SELECT `count` FROM some_table

I hope this helps you.

share|improve this answer

If you want to use something around object identifiers, use at least the standard double quotes: "

This works in MySQL, PostgreSQL, SQL Server, Oracle, etc. etc. For MySQL you might need the SQL mode ansi_quotes, depending on the default configuration:

SET sql_mode = 'ANSI_QUOTES';

Backticks ` are only used in MySQL, you learn a type of SQL that won't work in any other brand of DBMS.

share|improve this answer

It means you can have spaces in table names. Not particular appealing, of course. Same with SQL Server's [].

share|improve this answer

It can be helpful if you have a column with name that is reserved,

eg: You can query a statement like this:

select * from tablename group by `group`;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.