Wednesday, 15 July 2015

sql - Should I create a new entity for just one (string) field? -



sql - Should I create a new entity for just one (string) field? -

suppose have entity, example:

person

-id -name -address -phone

and want person have string , may repeated lot of times each person, illustration neighborhood, think should do:

person

-id -name -address -phone -idneighborhood

and create new table

neighborhood

-id -name

and of course, idneighborhood foreign key id of neighborhood.

now, thinking have create joins every time (let's utilize neighborhood in 90% of cases want utilize person), so, wrong?:

person

-id -name -address -phone -neighborhoodname

in save name of neighborhood, of course, repeated lot of times (in other case repeat lot of ids... so...)..

also, in particular case, neighborhood never grow, have name, that's why think it's improve this, not sure.. thing think of disadvantage can't create index of neighborhood , slower, or not?

this question want model. should model things in database relevant problem trying solve system.

are interested in neighbourhoods entity of own?

some reasons want create neighbourhood table:-

you end adding additional attributes neighbourhood (say, city or state) you end having 2 neighbourhoods same name, different (so need identity beyond name) you worried storage requirements , have relatively few neighbourhoods , lots of people (the id smaller in size) you want command master list of neighbourhoods can used (people select existing neighbourhood , can't come in old thing)

note apply same logic name column well. if database about people's names, same way should create neighbourhood column if modelling neighbourhoods help problem solving.

sql sql-server database-design

No comments:

Post a Comment