
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Will “create table table” work in MySQL since we cannot use reserved words as table name?
Let us first see a case wherein we use “create table table” while creating a table. An error will arise −
mysql> create table table( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100) );
This will produce the following output i.e. error −
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 'table( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100) )' at line 1
As you can see above, the word “table” is a reserved keyword, and we cannot use it as the name of the table. Therefore, to fix this, you need to wrap the table name using backticks.
Let us create the table again and set the table name as `table` with backticks −
mysql> create table `table`( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100) ); Query OK, 0 rows affected (0.81 sec)
Insert some records in the table using insert command −
mysql> insert into `table`(FirstName) values('Chris'); Query OK, 1 row affected (0.15 sec) mysql> insert into `table`(FirstName) values('Robert'); Query OK, 1 row affected (0.15 sec) mysql> insert into `table`(FirstName) values('David'); Query OK, 1 row affected (0.15 sec) mysql> insert into `table`(FirstName) values('Mike'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from `table`;
This will produce the following output −
+----+-----------+ | Id | FirstName | +----+-----------+ | 1 | Chris | | 2 | Robert | | 3 | David | | 4 | Mike | +----+-----------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- Can we use “When” as column name in CREATE TABLE statement?
- Can we use “year” as a column came in a MySQL Table?
- Should I name the username field in my MySQL table “name” or “user_name”?
- Error occurs when table name “references” is set while creating a table
- How to generate a “create table” command based on an existing table in MySQL?
- How can we use the MySQL reserved words as an identifier?
- Create a table named “select” in SQL databases?
- Purpose and table creation syntax of “Created temporary table”
- Purpose and table creation syntax of “Declared temporary table”
- Can we use “rank” as column name with MySQL8?
- MySQL: delete all rows containing string “foo” in sample table “bar”?
- Underscore as a table name in MySQL is possible?
- MySQL query error with a table named “order”?
- Can we use reserved word ‘index’ as MySQL column name?
- Fix Error in MySQL syntax while creating a table column with name “index”?
Advertisements