简体   繁体   English

在更新域(DB)实体时添加列或创建新表?

[英]Add a column or create a new table when updating a domain (DB) entity?

In my database I have a table called Person with rows for ID and name and this works fine for the time being. 在我的数据库中,我有一个名为Person的表,其中包含ID和名称行,并且暂时可以正常工作。 Later on, after deployment, I realized I want a Person to also have an address (a single address per person). 稍后,在部署之后,我意识到我也希望一个人也有一个地址(每个人一个地址)。 What is the best way to do this? 做这个的最好方式是什么? Update the table with a new column for the address or create a new table Address for the address and link the two tables with a reference? 使用地址的新列更新表或为地址创建新表地址,并将两个表与引用链接? Or, maybe, I should have one table Person, one table Address, and one table PersonAddressRelation with keys for both. 或者,也许我应该有一个表Person,一个表Address和一个表PersonAddressRelation,两者都具有键。

I know a bit about table normalization. 我对表规范化有些了解。 My question is: how to build a set a tables if you predict they might change? 我的问题是:如果您预测表可能会更改,则如何构建一个表?

always, in each table, use a primary, auto increment key; 始终在每个表中使用主自动递增键; and make sure that you have the best db structure from the start; 从一开始就确保您拥有最佳的数据库结构; why ? 为什么呢? because once you start pomping info, the db tables will increase, and you dont know how big they will get; 因为一旦开始弹出信息,数据库表就会增加,并且您不知道它们会增加多少; if lets say at 10 millions info's per table you need to add a new field, it's ok, it will take some time ... but if you try at 100 millions ... you are done ... game over ... so , do your best from the start and always identify each information by an unique id 如果说每张表有1千万个信息,您需要添加一个新字段,没关系,这将需要一些时间...但是如果您以1亿个尝试...您已经完成了...游戏结束...所以,从一开始就尽力而为,并始终通过唯一的ID识别每条信息

I suggest an extra address table. 我建议一个额外的address表。 That way you can add a foreign key to the person table and maybe you someday you need persons with more than one address. 这样,您可以将外键添加到person表中,也许有一天您需要具有多个地址的人员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM