开发者

Combine two tables or keep them separate?

开发者 https://www.devze.com 2023-03-12 23:44 出处:网络
Structure TableA (each row in TableA can map to one or more row in circle) Id Name TableB (each row in TableB can map to only one row in TableA)

Structure

TableA (each row in TableA can map to one or more row in circle)
    Id
    Name

TableB (each row in TableB can map to only one row in TableA)
    Id
    TableAId
    UniqueValue
开发者_如何学Go

Example Data

TableA
    1,Sooprise

TableB
    1,1,something
    2,1,somethingElse

So in this case, "UniqueValue" can only associate themselves to one row in TableA. Would it make more sense to combine the tables?

Structure

TableC
    Id
    Name
    UniqueValue

Example Data

TableC
    1,Sooprise,something
    2,Sooprise,somethingElse

I'm leaning more towards the first choice, but since there is a one to one mapping from B to A, these tables can be combined. I do understand that combining the tables would result in a data redundancy (Name) but maybe there can be exceptions made for not using two relational tables?


I'd keep the two tables separated. And I would create a view to get the next structure if needed.


I think the choice will be determined by what the tables are going to be used for. Two tables are probably the better design if you look at database space (Which may not be a concern), and if you are concerned about updated. (if 1,Sooprise becomes 1,Sooprise_New do you want to update all of the records in table B, or do you want the values to remain 1,Sooprise for some entries)?

I have found that for future changes in data structures its best to keep twp tables


It depends. What are the tables used for? If you find yourself needing data from multiple relational tables at the same time, then it's probably a good idea to join them. If their use is largely separate and you feel separate tables enhance clarity, then keep them separate.

0

精彩评论

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