Take the 2-minute tour ×
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.

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
add comment

4 Answers 4

up vote 15 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 if status was a keyword:

select status from some_table

But the following would be parsed correctly:

select `status` from some_table

I hope this helps you.

share|improve this answer
3  
Upvoted your answer, but just to nitpick, "status" is actually not a keyword, and does not produce an error. –  Shlomi Noach Aug 25 '12 at 10:48
    
Thank you Brownstone. Previously i was assuming that like in java, we can't use identifiers/reserved-words in mysql queries. –  Satish Pandey Aug 25 '12 at 11:07
    
@SatishPandey You can't use reserved keywords as identifiers unless quoted, that is true - it's just that status is not a reserved word. –  Michael Aug 26 '12 at 19:01
    
@Michael I agree with you, this is very clear to me. –  Satish Pandey Aug 27 '12 at 5:16
add comment

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

share|improve this answer
    
Thank you for the answer Rob –  Satish Pandey Aug 25 '12 at 10:53
    
Is the same applied to MS SQL Servers? –  Satish Pandey Aug 25 '12 at 11:16
    
With [ and ] instead, yes. –  Rob Farley Aug 25 '12 at 11:58
add comment

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
    
+1 - Thank you Frank for this important info. –  Satish Pandey Aug 25 '12 at 11:46
add comment

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
add comment

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.