1

What does the ` symbol actually mean in MySQL?

This works:

INSERT INTO person(`name`, `roll_no`, `gender`) VALUES('person1', 1, 'male');

Whereas this throws a syntax error:

INSERT INTO person(name, roll_no, gender) VALUES('person1', 1, 'male');
Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
  • possible duplicate of [Syntax error due to using a reserved word as a table or column name in MySQL](http://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql) – nietonfir May 06 '14 at 20:48

1 Answers1

8

The ` just tells MySQL to expect a column name, since name is a reserved keyword in SQL.

SELECT `name` in MySQL is the equivalent of SELECT [name] in T-SQL.


Bonus:

I highly recommend using MySQL Workbench instead of the usual phpMyAdmin. One of the great advantages of using a proper management studio is that this would've been quite obvious:

Notice that name is highlighted differently, showing that it is a reserved keyword, and needs to be escaped as `name`.

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
  • It's worth noting that neither the backtick nor Microsoft's `[..]` are valid in standard SQL. The SQL standard requires double quotes to quote identifiers with "illegal" characters. Both, MySQL and SQL Server do also accept (or can be configured to accept) object names quoted according to the SQL standard (e.g. `"name"`) –  Dec 06 '13 at 07:58
  • 1
    `name` is NOT a reserved keyword, and does not need to be escaped. That said, I agree that keywords should be avoided where possible, and reserved (key)words should be avoided altogether. – Strawberry Dec 06 '13 at 09:46