Search code examples
relational-databasedatabase-theory

Database issue: 2 tables with identical structure because of the quality of the data


I have a database with one table where I store two different types of data. I store a Quote and a Booking in a unique table named Booking.

First, I thought that a quote and a booking is the same since they had the same fields. But then a quote is not related to a user where a booking is. We have a lot of quotes in our database which pollutes the table booking with less important data.

I guess it makes sense to have two different tables so they can also evolve independently.

  • Quote
  • Booking

The objective is to split the data into junk data (quote) and the actual data (booking). Does it make sense in the relational-database theory?


Solution

  • I'd start by looking for the domain model to tie this to - is a "quote" the same logical thing as a "booking"? Quotes typically have a different lifecycle to bookings, and bookings typically represent financial commitments. The fact they share some attributes is a hint that they are similar domain concepts, but it's not conclusive. Cars and goldfish share some attributes - age, location, colour - but it's hard to think of them as "similar concepts" at any fundamental level.

    In database design, it's best to try to represent the business domain as far as is possible. It makes your code easy to understand, which makes it less likely you'll introduce bugs. It often makes the code simpler, too, which may make it faster.

    If you decide they are related in the domain model, it may be a case of trying to model an inheritance hierarchy in the relational database. This question discusses this extensively.