createtable`select`(idint);QueryOK,0rowsaffected(0.19sec) If this mode is enabled, you can also use backticks (&ld"/> createtable`select`(idint);QueryOK,0rowsaffected(0.19sec) If this mode is enabled, you can also use backticks (&ld">

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

How to use MySQL reserved words as identifiers?

WBOY
WBOYforward
2023-09-10 22:45:11614browse

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)

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)

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete