After reading a couple of answers and comments on some SQL questions here, and also hearing that a friend of mine works at a place which has a policy which bans them, I\'m w
The main use of backticks (`) in SQL is to use them in situations where you are going to call them again in upcoming clauses. In every other time it is recommended to use double quotes("").
For example
SELECT CONCAT(Name, ' in ', city, ', ', statecode) AS `Publisher and Location`,
COUNT(ISBN) AS "# Books",
MAX(LENGTH(title)) AS "Longest Title",
MIN(LENGTH(title)) AS "Shortest Title"
FROM Publisher JOIN Book
ON Publisher.PublisherID = Book.PublisherID WHERE INSTR(name, 'read')>0
GROUP BY `Publisher and Location`
HAVING COUNT(ISBN) > 1;
In the above statement do you see how Publisher and Location
is used again in GROUP BY
clause.
Instead of using
GROUP BY Name, city, statecode
I just used
GROUP BY
Publisher and Location
Only when such situations arise, it is useful to use backticks. In all other times using double quotes is recommended.
To me it makes a lot of sense to use them at all times when dealing with field names.
If you ask to me, backticks should always be used. But there are some reasons why a team may prefer not to use them.
Advantages:
Disadvantages:
Well, as far as I know, the whole purpose of using backticks is so you can use names that coincide with reserved keywords. So, if the name isn't colliding with a reserved keyword, I don't see any reason to use backticks. But, that's no reason to ban them, either.
It's a lot easier to search your code-base for something in backticks. Say you have a table named event
. grep -r "event" *
might return hundreds of results. grep -r "\`event\`" *
will return anything probably referencing your database.