0

Database name : test table names : order, order_shipping,order_payment

The query below gives me error

INSERT INTO order(order_status,customer_id) values('booked',1) 

error : 1064 - 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(order_status,customer_id) values('booked',1)' at line 1

But the exact same query will work if i add database name before tablename

INSERT INTO test.order(order_status,customer_id) values('booked',1) 

result : insertion successfull

I renamed tablename 'order' to 'order_main' and it works without database name

INSERT INTO order_main(order_status,customer_id) values('booked',1) 

insertion successfull

My question is why does not my original query work without database name attached to table name. Is it because I have other tables starting with this table name ???

table in my database : order, order_shipping,order_payment

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
Raj
  • 1,945
  • 20
  • 40

1 Answers1

4

order is a reserved keyword within MySQL. If you want to use it as an identifier, enclose it in backticks:

INSERT INTO `order` (order_status,customer_id) values('booked',1) 

In the second query, you specify a full identifier, which MySQL does not mistake for a keyword. Hence, it works without problems.

Sirko
  • 72,589
  • 19
  • 149
  • 183
  • Thanks Sirko.. Did not think like that.... Thanks also for taking the time to explain it to me... :) – Raj Jul 29 '13 at 19:10