Search code examples
sqlmany-to-many

Database Relationships inquiry


Need some guidance with relationship design. Scenario: User can have up to 4 cars at anytime, cars have their own properties(color, make, cost). Is it fair to say that there is a "many to many" relationship between user and car, and use a link table between them. Or is it a one user to many cars and just insert carID into user table?

Thanks


Solution

  • Many-to-many is a situation where (in your world) a user can own several cars, but also a car can have many owners (users). Your case sounds like a one to many scenario.

    The classic example of many to many is students-courses, where a student can enlist in many courses and each course has many students.

    In your case, if each car has just 1 owner, this is a one to many case, and I would just add a userId column in the cars table. This would support unlimited, more than 4 cars per user.