Home > Database > Mysql Tutorial > How to use MySQL reserved words as identifiers?

How to use MySQL reserved words as identifiers?

WBOY
Release: 2023-09-10 22:45:11
forward
655 people have browsed it

How to use MySQL reserved words as identifiers?

We must use quotes to use reserved words as identifiers. Quotes can be single or double quotes, depending on the ANSI_QUOTES SQL mode.

If this mode is disabled, the identifier quote character is a backtick ("`"). Consider the following example, we have created a table called 'select' −

mysql> create table `select`(id int);
Query OK, 0 rows affected (0.19 sec)
Copy after login

If this mode is enabled, you can use both backtick ("`") and double quote ("") as identifiers reference character. Consider the following example, we have created a table named 'trigger' −

mysql> Create table "trigger" (id int);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '"trigger" (id int)' at line 1

mysql> Set sql_mode = 'ANSI_Quotes';
Query OK, 0 rows affected (0.03 sec)

mysql> Create table "trigger" (id int);
Query OK, 0 rows affected (0.17 sec)

mysql> Create table `DESCRIBE`(id int);
Query OK, 0 rows affected (0.11 sec)
Copy after login

The above query shows that we can use both backticks ("`") and double quotes after enabling "ANSI_QUOTES" mode ("") as an identifier quote character.

The above is the detailed content of How to use MySQL reserved words as identifiers?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template