Mysql – Car Dealarship Database Design

database-designMySQL

I have to design the following sentences for a company that sells different vehicles:
"The database must keep track of everyone involved(customer and staff) in the sales for vehicles. The sale price, profit and commission from that profit also needs to be recorded."

I came across many ER diagrams to model such a scenario which involves a ternary relationship between Vehicles, Staff and Customer as can be seen here.(ER1)

And another one where the Sales in actually an Entity? like this.(ER2)

Initially, I was drawing my diagram like this(3) but as it says, the diagram is not accurate and I'm not sure why.

What exactly is the difference between the concept that these two diagrams(ER1 and ER2) explain? It would be a lot of help if someone could explain the difference between the two models and which one is better suited for what I want to record in the database.

If any clarification is needed please let me know.

Best Answer

the first diagram you can't realized in a rdms, you need to make sales always to an entity, to represent the relation ship.

if we take the third diagram, you would have all the wanted data, but you couldn't make foreign keys work, because of the ring relationship.( every row that is referenced mus exist before, this doesn't work in a ring relationship).

now you have two possibilities:

  1. you have to represent the trinary relationship in an entity, and you wouldn't have the eer 1 any more, as sales is an entity with foreign keys to all three tables(entities)
  2. you put the relationship in your application code

the first gets you your second approach.

The second doesn't show the relationship with foreign keys, so you would add the information by adding comments to the tables.