
- 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
What is the MySQL syntax error in this query – Creating a table with reserved keyword?
Let’s say we tried creating a table with name “groups”, which is a reserved keyword in MySQL You cannot use “groups” because groups is a reserved keyword in MySQL.
Following error occurred while creating a table with name “groups” −
mysql> create table groups −> ( −> id int, −> name varchar(40) −> ); 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 'groups ( id int, name varchar(40) )' at line 1
In order to create a table with reserved keyword, you need to use the concept of backticks(``).
Let us create a table −
mysql> create table `groups` -> ( −> id int, −> name varchar(40) −> ) −> ; Query OK, 0 rows affected (3.08 sec)
Insert some records into the table with the help of insert command −
mysql> insert into `groups` values(10,'John'); Query OK, 1 row affected (0.30 sec) mysql> insert into `groups` values(11,'Bob'); Query OK, 1 row affected (0.32 sec) mysql> insert into `groups` values(12,'Mike'); Query OK, 1 row affected (0.40 sec)
Display records from the table using select statement
mysql> select *from `groups`;
This will produce the following output −
+------+------+ | id | name | +------+------+ | 10 | John | | 11 | Bob | | 12 | Mike | +------+------+ 3 rows in set (0.04 sec)
- Related Articles
- While creating a MySQL table use the reserved keyword ‘Key’
- Fix Error in MySQL syntax while creating a table column with name “index”?
- MySQL syntax error (in SELECT query) while using ‘group’ as table name
- MySQL query error with a table named “order”?
- What is the syntax for input parameters (variables) in a MySQL query?
- Declare syntax error in MySQL Workbench?
- Creating a table with MySQL - Hibernate
- Error occurs when table name “references” is set while creating a table
- What is the use of the LIMIT keyword in MySQL query?
- Creating a table with a TIMESTAMP field in MySQL?
- What is the syntax in MySQL to get the column names of a table?
- How to resolve the error that occurs while using a reserved word as a table or column name in MySQL?
- Resolve MySQL ERROR 1064 (42000): You have an error in your syntax?
- Creating a JavaScript array with new keyword.
- Is name a reserved word in MySQL?

Advertisements