简体   繁体   中英

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. 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.

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

I suggest an extra address table. That way you can add a foreign key to the person table and maybe you someday you need persons with more than one address.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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