简体   繁体   中英

Why am I getting jest errors when creating this table?

I'm trying to use primary key for more than one place; however, in my table I get jest error about multiple primary key defined-get.

Below is my code:

create table orders (
 order_id int AUTO_INCREMENT, 
 ordered_from int, 
 PRIMARY KEY (order_id), 
 FOREIGN KEY (ordered_from) REFERENCES restaurants(restaurants_id), 
 delivery_man int, 
 PRIMARY KEY (order_id), 
 FOREIGN KEY (delivery_man) REFERENCES delivers(deliver_id), 
 user_num int, 
 PRIMARY KEY (order_id), 
 FOREIGN KEY (user_num) REFERENCES users(user_id)
);

Please help me out. What would be the right Syntax?

I'm trying to use the id from all of my tables in one table of the order.

In orders table, Im trying to put the user, delivery man, and the restaurant.

Thanks.

create table orders ( order_id int AUTO_INCREMENT, ordered_from int, PRIMARY KEY (order_id), FOREIGN KEY (ordered_from) REFERENCES restaurants(restaurants_id), delivery_man int, PRIMARY KEY (order_id), FOREIGN KEY (delivery_man) REFERENCES delivers(deliver_id), user_num int, PRIMARY KEY (order_id), FOREIGN KEY (user_num) REFERENCES users(user_id) )

A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY KEY in another table. The restaurants_id , deliver_id and user_id needs to be primary key in the restaurants , delivers and users tables respectively.

Change the above declaration syntax as mentioned below

CREATE TABLE orders (
 order_id int AUTO_INCREMENT, 
 ordered_from int,
 delivery_man int, 
 user_num int, 
 PRIMARY KEY (order_id), 
 FOREIGN KEY (ordered_from) REFERENCES restaurants(restaurants_id), 
 FOREIGN KEY (delivery_man) REFERENCES delivers(deliver_id), 
 FOREIGN KEY (user_num) REFERENCES users(user_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