MySQL Forums
Forum List  »  Newbie

Re: How to get rid of Composite Primary Key
Posted by: Peter Brawley
Date: May 03, 2021 04:18PM

You don't need a composite order_item PK, a surrogate PK also works ...

create table Order_Items 
( order_item_id int unsigned primary key auto_increment, 
  order_id int not null 
, item_id int not null 
, qty int not null 
, price decimal(9.2) not null 
, foreign key order_id references Orders( id ) 
, foreign key item_id references Items( id ) /* Assumes an Items table that defines anything that can be ordered */ 
); 

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.