简体   繁体   中英

Database design: invoice modeling

I'm currently working on a project in which i'm about to make a conceptual model for car retail. My major problem is dealing with 1 to 1 realtionship between Invoice_Line table, which is obviously in N-1 relationship with Invoice table, and a table called Car which is supposed to hold information about specific car with it's unique registration number. As far as i know it wouldnt be a problem if i have made the Car table containing only information about specific type of a car, that is it's model, class, etc. However what i want is the invoice looking like that:

  1. ...car_registration_number... ...price... ...date...
  2. ...

That would mean making a 1 to 1 realtionship between invoice_line and table with specific car_id's, which i want to avoid at all cost. What are the further possibilities to solve that? Because of distinguishable car's each invoice line would hold only 1 car, which is my way of designing it.

An invoice line appears in one invoice so say so in Invoice_Line :

UNIQUE NOT NULL (invoice, invoice_line_number)

The invoices must all appear in Invoice so say so:

FOREIGN KEY (invoice_number) REFERENCES Invoice (invoice_number)

A car is unique in Invoice_Line so say so:

UNIQUE NOT NULL (car_registration_number)

The cars must all appear in Car so say so:

FOREIGN KEY (car_registration_number) REFERENCES Car (car_registration_number)

There is a 1:1 relationship between invoice lines and invoiced cars. But it is not a problem because that relationship is represented by car + invoice line pairs (car + invoice + invoice line number triplets) in Invoice_Line .

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