- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to resolve the error that occurs while using a reserved word as a table or column name in MySQL?
152 Lectures 16 hours
87 Lectures 5.5 hours
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.
- Is name a reserved word in MySQL?
- 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
- Fix Error in MySQL syntax while creating a table column with name “index”?
- While creating a MySQL table use the reserved keyword ‘Key’
- Select the table name as a column in a UNION select query with MySQL?
- Will “create table table” work in MySQL since we cannot use reserved words as table name?
- Why the #1054 - Unknown column error occurs in MySQL and how to fix it?
- What is the MySQL syntax error in this query – Creating a table with reserved keyword?
- Underscore as a table name in MySQL is possible?
- Display an error while inserting duplicate records in a MySQL table
- Can a number be used to name a MySQL table column?
- Resolve the error Column count doesn’t match value count in MySQL?