Question

I am trying to create a simple database of a theoretical car rental company. The following picture shows the relationships I currently have.

enter image description here

However, when I try to assign more than one car to a single customer, I get the following error message:

enter image description here

If anyone could advise me as to why this is coming up and what to change I would be very greatful, if more information is needed to figure this out just ask! Thanks

Was it helpful?

Solution 2

Your ER diagram's wrong. Assuming you want Zero, One Customer --> Many Cars, then the proper pattern is to insert the foreign key of the 0,1 into the table of the Many.

So your Cars table should have a Foreign key of CustomerId.

Customer table shouldn't know about Cars at all for normality.

EDIT: Looking at the requirements/model, chances are this is many to many. I.e. Many customers over time rent a car or cars. In this case to maintain normality you need a junction table - e.g. cars-customers that has two primary keys, CustomerId and CarId. That's also where you'd put information about that relationship, like dates rented and the like.

OTHER TIPS

CustomerID is a primary key, and is being duplicated on your second line. Primary keys must be unique.

You have created a 1 to 1 relationship between customers and bookings. That means that every customer may have only one booking and every booking may only have one customer. That's why you are having to duplicate that CustomerID in order to add a booking with a different car.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top