简体   繁体   中英

Getting error 1064 while running query for table creation?

I already have created customers and products table.I am getting this error while running following command in phpmyadmin.
CREATE TABLE orders ( id INT NOT NULL AUTO_INCREMENT, orderNumber INT, productId INT, customerId INT, orderDate DATETIME default CURRENT_TIMESTAMP, PRIMARY KEY(id), PRIMARY KEY (customerId) REFERENCES customers(id) , FOREIGN KEY (productId) REFERENCES products(id) );

1064 error

Can not create more than one primary keys.

Try this code.

CREATE TABLE orders (
id INT NOT NULL AUTO_INCREMENT,
orderNumber INT,
productId INT,
customerId INT,
orderDate DATETIME default CURRENT_TIMESTAMP,
PRIMARY KEY(id),
FOREIGN  KEY (customerId) REFERENCES customers(id) ,
FOREIGN KEY (productId) REFERENCES products(id));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM