modeling - Handling missing values in a database schema? -


suppose have following table schema

month varchar(10) hasrain boolean year integer 

now suppose particular year, have values 11 months, no value the left on month (let's call september).

is more correct to:

  1. put record in 0 value, or

  2. leave no record month

my question is: how model absence of information in database schema?

if information entity not needed understand entity, these not cognitively dependant on each other , can normalised.

what means in general practice should make separate tables 2 entities , use foreign keys refer between them.

imagine this:

table weather_month: ------------ month enum('jan', 'feb', mar' ...) not null, year mediumint not null, weather_id mediumint, primary key(month, year)  table weather: ------------ weather_id mediumint not null rain boolean not null, clouds enum('clear', 'sparse', 'thick', 'cumulus', ...) not null, temperature enum('freezing', 'thawing', 't-shirt weather', 'hot', ...) not null 

this example shows how either know weather is, or don't.

if put lots , lots of nullable fields weather_month table (as quite quite common way of doing this), not clear in setup have either observed weather or did not.

relational databases use null "i have no value", should consider how use it, because database design make should speak data structure , if speaks itself, won't have explain people. saves time.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -