开发者

Which is a better design, storing days in database

I would like to let user see the date about the course. For example, a computer course will held on

1/9, 2/9, 3/9.

So, how to store these day in the database? one column the store a string like this:

1/9/2011,2/9/2011,3/9/2011

or a separate table like this:

event_id   dat开发者_开发技巧e
1          1/9/2011
1          2/9/2011
1          3/9/2011

Thank you.


The separate table is the right design, because that's how your schema will be normalized. A table column should hold a single type of value.

First normal form of database normalization states:

Every row-and-column intersection contains exactly one value from the applicable domain (and nothing else).


Almost every database under the sun has a DATE datatype, which will do exactly this.

Also: use data normalisation: The separate table is the way to go.


I would have a table with (at least) 3 columns, using the date type for the start and end date

event_id start_date end_date
1         1/9/2011  3/9/2011


A column should store exactly one value only. Separate table.

As a CSV, how can you

  • find course starting 2/9/2001
  • order by
  • delete 2/9/2001, add 4/9/2011 etc


both methods has it own benefits

first method will suit for simple data structure,
that's mean your data size could be small,
your project job scope is small,
and you don't wish to spent too many effort on that

the bad is hard to maintain in long run

second method will better for normalization
but require more code / JOIN to get the same piece of information
(you can do in one step in the first method)


Is BAD for date string in d/m/Y,
let the presentation language to determine the locale

ISO format YYYY-MM-DD will be the better choice

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜