- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 can I make a table in MySQL called “order”?
As you know, order is a keyword in MySQL, you cannot give table name order directly. You need to use backtick around the table name order. Backtick allow a user to consider the keyword as table or column name.
The syntax is as follows
CREATE TABLE `order` ( yourColumnName1 dataType, yourColumnName2 dataType, yourColumnName3 dataType, . . . . N );
Let us create a table. The query to create a table is as follows
mysql> create table `order` - > ( - > Id int, - > Price int - > ); Query OK, 0 rows affected (0.66 sec)
Insert some records in the table using insert command.
The query is as follows
mysql> insert into `order` values(1,200); Query OK, 1 row affected (0.21 sec) mysql> insert into `order` values(2,100); Query OK, 1 row affected (0.17 sec) mysql> insert into `order` values(3,300); Query OK, 1 row affected (0.20 sec) mysql> insert into `order` values(4,1200); Query OK, 1 row affected (0.13 sec) mysql> insert into `order` values(5,1000); Query OK, 1 row affected (0.18 sec) mysql> insert into `order` values(6,7000); Query OK, 1 row affected (0.20 sec) mysql> insert into `order` values(7,900); Query OK, 1 row affected (0.16 sec) mysql> insert into `order` values(8,10000); Query OK, 1 row affected (0.18 sec) mysql> insert into `order` values(9,1100); Query OK, 1 row affected (0.30 sec) mysql> insert into `order` values(10,500); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement.
The query is as follows
mysql> select *from `order`;
The following is the output
+------+-------+ | Id | Price | +------+-------+ | 1 | 200 | | 2 | 100 | | 3 | 300 | | 4 | 1200 | | 5 | 1000 | | 6 | 7000 | | 7 | 900 | | 8 | 10000 | | 9 | 1100 | | 10 | 500 | +------+-------+ 10 rows in set (0.00 sec)
If you do not use backtick symbol around the table name set as a keyword, you will get an error.
The error is as follows
mysql> select *from order; 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 'order' at line 1
Therefore, to fix this error and use a keyword as table or column name, you need to use backtick symbol around the name.
Advertisements