Moon
Moon

Reputation: 22565

Is using backticks necessary?

When I write an SQL statement, I usually write it like this

SELECT COUNT(*) FROM catalogsearch_query AS main_table

But I found that some people write SQL statements like

SELECT COUNT(*) FROM `catalogsearch_query` AS `main_table`

Do I have to use `?

Upvotes: 2

Views: 90

Answers (2)

codaddict
codaddict

Reputation: 454960

From MySql docs:

Database, table, index, column, and alias names are identifiers. An identifier may be quoted or unquoted. If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it.

We use the backtick ` for quoting.

Upvotes: 0

reko_t
reko_t

Reputation: 56430

You don't have to use backticks. However when you're using reserved keywords as table or field names, then you have to enclose them in backticks for them to work.

Upvotes: 5

Related Questions