
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to resolve the error that occurs while using a reserved word as a table or column name in MySQL?
This error occurs when you try to use a reserved word as a table or column name. It can occur due to −
Case 1: Whenever you use reserved word as a table name −
mysql> create table insert −> ( −> Id int −> );
The error is as follows −
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 'insert ( Id int )' at line 1
The above error occurred because the word ‘insert’ is a keyword in MySQL.
Case 2 − Whenever you use reserved word as a column name in MySQL.
mysql> create table Customers −> ( −> Add int −> );
The error is as follows −
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 'Add int )' at line 3
The above error occurred because the column name ‘Add’ is a reserved word in MySQL.
To avoid the above error, you need to know about all the reserved words of MySQL
Some of the MySQL reserved words are as follows −
Insert Add Is Key Like etc.
The complete list of MySQL reserved keywords are as follows. This is the official website of MySQL − https://dev.mysql.com/doc/refman/5.7/en/keywords.html
Use a backtick with the reserved keyword to solve this issue.
Note - You cannot use a reserved keyword for table or column name. However, including them with backtick would be considered correct.
For Example −
create table `insert`
Demo of backtick with table as well as column name.
mysql> create table `Insert` −> ( −> `Add` int −> ); Query OK, 0 rows affected (0.59 sec)
With the help of backtick, you will not get any error.
- Related Articles
- Can we use reserved word ‘index’ as MySQL column name?
- Error occurs when table name “references” is set while creating a table
- MySQL syntax error (in SELECT query) while using ‘group’ as table name
- Is name a reserved word in MySQL?
- Fix Error in MySQL syntax while creating a table column with name “index”?
- While creating a MySQL table use the reserved keyword ‘Key’
- Resolve the error Column count doesn’t match value count in MySQL?
- Will “create table table” work in MySQL since we cannot use reserved words as table name?
- What is the MySQL syntax error in this query – Creating a table with reserved keyword?
- Why the #1054 - Unknown column error occurs in MySQL and how to fix it?
- Select the table name as a column in a UNION select query with MySQL?
- Display an error while inserting duplicate records in a MySQL table
- How to ignore using variable name as a literal while using push() in JavaScript?
- How to get the primary key “column name” of a specific table in MySQL?
- Resolve the MySQL error 'TYPE=MyISAM'?
