Re: Need help with DB design/model
Posted by: Peter Brawley
Date: November 24, 2014 03:13PM

* Each carrier uses a tracking number system (so, no order is shipped without a tracking number)

* You can have one or more orders that are shipped on one single tracking number (this is the part I'm having a problem with)

* Once a tracking number is used, it cannot be re-used

Lots of possibilities. Assuming an orders table PK orderID and no chance one carrier's tracking# can duplicate another's ...

create table ordertracking( 
  trackingno varchar(64) primary key, 
  orderID, 
  foreign key(orderID) references orders(orderID) 
);

If cross-carrier duplication can't be ruled out ...

create table ordertracking( 
  carrier varchar(32),
  trackingno varchar(64), 
  primary key(carrier,trackingno),
  orderID, 
  foreign key(orderID) references orders(orderID) 
);

Or if there's a carriers table with carrierID PK ...

create table ordertracking( 
  carrierID int,
  trackingno varchar(64), 
  primary key(carrierID,trackingno),
  orderID, 
  foreign key(orderID) references orders(orderID) 
);

Options: ReplyQuote


Subject
Written By
Posted
November 24, 2014 01:58PM
Re: Need help with DB design/model
November 24, 2014 03:13PM


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.