开发者

I have 10 database tables 6 of them being link tables, should I make a general LinkTable?

开发者 https://www.devze.com 2023-01-30 06:07 出处:网络
I have 10 database tables A, B, C, D, E, F, G, H, I and J. Four of them are necessary, but six of them are just link tables that link between those four tables. I am considering building a generic lin

I have 10 database tables A, B, C, D, E, F, G, H, I and J. Four of them are necessary, but six of them are just link tables that link between those four tables. I am considering building a generic link table for this so

A, B, C, D, Link

Performs the same way as before except that the Link table provides all linking what the old six tables used to do. I need three columns for the Link table (subject, target, type).

Do you think this makes sense or is a sensible approach?

If it makes any difference, the size of the Link table should not get big. The type column i开发者_如何学Gos TINYINT. One of the link subjects is User, and that pretty much defines how big the entire link table can get. There will be some what 5% more rows in the table than there are rows in the User table.


Personally, no I wouldn't do this.

Yes, it might look "excessive" to have six link tables for four base data tables. But really: do you gain from having just a single link table, but then you have to start adding a type to the link (it's a link from table A to table D or something else), and it all gets rather messy.

To me, the clarity of being able to see that two tables are linked, because there's a link table between them, is much more important than having one or two tables fewer. That really doesn't make a big impact in any way - neither in terms of disk space, nor in terms of performance is this going to be beneficial.....

So again: why bother? Have a clear and proper design, and just accept the fact that relational databases need a few helper tables between their main tables to make the "magic" work - and don't worry too much about that fact.....

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号