mysqlcreate-tablebridgemysqladmin

Why Is MySQL Bridge Table Not Working?


I currently have the following tables: Category, Product, Payment, User.

The following is MySQL script for bridge table:

CREATE TABLE Order
(
  FOREIGN KEY UID MEDIUMINT REFERENCES User (UID),
  FOREIGN KEY PID MEDIUMINT REFERENCES Product(PID),
  FOREIGN KEY PayID REFERENCES Payment(PayID),
  PRIMARY KEY (UID,PID)
)

I am getting the following error in MySql:

#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 (
  FOREIGN KEY UID MEDIUMINT REFERENCES User (UID),
  FOREIGN KEY PID MEDI' at line 1

Please note that this is the last table.


Solution

  • Order is a reserved word. You should either change it or you can escape the name with backticks:

    CREATE TABLE `Order` ( .... )