database design - SQL one to one relationship vs. single table -
consider data structure such below user has small number of fixed settings.
user
[id] int identity not null, [name] nvarchar(max) not null, [email] vnarchar(2034) not null
usersettings
[settinga], [settingb], [settingc]
is considered correct move user's settings separate table, thereby creating one-to-one relationship users table? offer real advantage on storing in same row user (the obvious disadvantage being performance).
you split tables 2 or more 1:1 related tables when table gets wide (i.e. has many columns). hard programmers have deal tables many columns. big companies such tables can have more 100 columns.
so imagine product table. there selling price , maybe price used calculation , estimation only. wouldn't have 2 tables, 1 real values , 1 planning phase? programmer never confuse 2 prices. or take logistic settings product. want insert products table, these logistic attributes in it, need set of these? if 2 tables, insert product table, , programmer responsible logistics data care logistic table. no more confusion.
another thing many-column tables full table scan of course slower table 150 columns table half of or less.
a last point access rights. separate tables can grant different rights on product's main table , product's logistic table.
so in all, rather rare see 1:1 relations, can give clearer view on data , performance issues , data access.
edit: i'm taking mike sherrill's advice , (hopefully) clarify thing normalization.
normalization avoiding redundancy , relateded lack of consistence. decision whether hold data in 1 table or more 1:1 related tables has nothing this. can decide split user table in 1 table personal information first , last name , school, graduation , job. both tables stay in normal form original table, because there no data more or less redundant before. column used twice user id, not redundant, because needed in both tables identify record.
so asking "is considered correct normalize settings separate table?" not valid question, because don't normalize putting data 1:1 related separate table.
Comments
Post a Comment