Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of grave accent (AKA backtick) quoted characters in MySQL?

Tags:

sql

mysql

I was wondering why some tutorials and other MySQL management tools use grave accent (`) in their queries like this one below:

SELECT `TableA`.`FieldA`, `TableA`.`FieldB`, `TableA`.`FieldC`  FROM `Databasename`.`TableA` 

When it displays the same result with this query below:

SELECT FieldA, FieldB, FieldC FROM TableA 
like image 276
John Woo Avatar asked Oct 22 '11 03:10

John Woo


People also ask

What does Backtick do in MySQL?

Backticks are used in MySQL to select columns and tables from your MySQL source. In the example below we are calling to the table titled Album and the column Title . Using backticks we are signifying that those are the column and table names.

Should you use Backticks in SQL?

Backticks ( ` ) are used to indicate database, table, and column names. Unless you're using reserved or conflicting words for table and database names, you'll not need to use them.


1 Answers

The grave is more commonly referred to as a "backtick", which MySQL uses to escape MySQL reserved words.

Wrapping everything in backticks is very common in PHPMyAdmin and various examples because most would rather name tables and columns whatever they like without worrying about naming errors. I don't agree with the practice personally...

like image 137
OMG Ponies Avatar answered Oct 09 '22 13:10

OMG Ponies