Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you have 2 tables with identical structure in a good DB schema?

2 tables:
- views
- downloads

Identical structure:
item_id, user_id, time

Should I be worried?

like image 830
Emanuil Rusev Avatar asked May 31 '10 13:05

Emanuil Rusev


3 Answers

I don't think that there is a problem, per se.

When designing a DB there are lots of different parameters, and some (e.g.: performance) may take precedence.

Case in point: even if the structures (and I suppose indexing) are identical, maybe "views" has more records and will be accessed more often. This alone could be a good reason not to burden it with records from the downloads.

Also, the fact that they are indentical now does not mean they will be in the future: views and downloads are different, after all, so sooner or later one or both could grow an extra field or two.

like image 200
p.marino Avatar answered Oct 02 '22 00:10

p.marino


These tables are the same NOW but may schema change in the future. If they represent 2 different concepts it is good to keep them separate. What if you wanted to have a foreign key from another table to the downloads table but not the views table, if they were that same table you could not do this.

like image 35
krock Avatar answered Oct 02 '22 00:10

krock


I think the answer has to be "it depends". As someone else pointed out, if the schema of one or both tables is likely to evolve then no. I can think of other cases well (simplifying the security model by allow apps/users access to one or the other).

Having said this, I work with a legacy DB where this is a problem. We have multiple identical tables for customer invoices. Data is actually moved between then at different stages in the processing life-cycle. It makes for a complicated mess when trying to access data. It would have been easily solved by a state flag in the original schema, but we now have 20+ years of code written against the multi-table version.

Short answer: depends on why they are the same schema :).

like image 30
David Avatar answered Oct 02 '22 01:10

David