SQL
database
backticks
field names
syntax

Using backticks around field names

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Backticks are MySQL-style identifier quotes. They are used around table names, column names, and similar identifiers when the name would otherwise be ambiguous, invalid, or conflicting with a reserved keyword. They are not string quotes, and they are not portable SQL syntax across all databases.

What Backticks Actually Quote

In MySQL and MariaDB, backticks quote identifiers such as:

  • table names
  • column names
  • index names
  • database names

Example:

sql
SELECT `order`, `group`
FROM `user_data`;

Here the backticks tell MySQL to interpret those tokens as identifiers even though order and group are reserved words.

When You Need Them

You need backticks when an identifier:

  • is a reserved keyword
  • contains spaces
  • contains special characters such as dashes
  • would otherwise be parsed incorrectly
sql
SELECT `first name`, `user-id`
FROM `customer records`;

Without backticks, that statement is either invalid or parsed as something else.

When You Do Not Need Them

For ordinary names like users, user_id, or created_at, backticks are optional in MySQL.

sql
SELECT user_id, created_at
FROM users;

Many teams avoid backticks by adopting simple snake_case naming rules and by avoiding reserved words in schema design.

Backticks Are Not Portable SQL

This is where many developers get tripped up. Backticks are MySQL-specific style. PostgreSQL and standard SQL use double quotes for identifiers. SQL Server often uses square brackets.

So this:

sql
SELECT `order` FROM `items`;

is a MySQL-style statement, not a universally portable SQL statement.

If cross-database portability matters, good schema naming is better than depending on quoted reserved words.

Backticks vs String Literals

This is the most common syntax mistake:

  • backticks quote identifiers
  • single quotes quote string values
sql
SELECT `name` FROM users WHERE `status` = 'active';

If you write WHERE status = active``, MySQL treats active like an identifier, not a string literal.

Best Practice

The best long-term practice is not “always backtick everything” but “name things so quoting is rarely necessary.”

For example, customer_order is better than order, and group_name is better than group.

Quoting is still useful, especially in generated SQL or when working with legacy schemas, but it should not become an excuse for poor naming.

In practice, backticks are most often a compatibility tool for legacy schemas. New schemas are usually easier to maintain when they avoid reserved words and unusual characters in the first place.

Common Pitfalls

The biggest mistake is confusing backticks with single quotes and accidentally turning string values into identifiers.

Another mistake is relying heavily on MySQL-specific quoting in code that may later move to a different database.

A third mistake is accepting reserved-word schema names when a clearer identifier would avoid the problem entirely.

Summary

  • Backticks quote identifiers in MySQL and MariaDB.
  • Use them when names collide with reserved words or contain unusual characters.
  • Do not use backticks for string literals; use single quotes for values.
  • Backticks are not portable SQL syntax across all databases.
  • The cleanest solution is usually better schema naming, not more quoting.

Course illustration
Course illustration

All Rights Reserved.