问题描述:

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 date

1 1/9/2011

1 2/9/2011

1 3/9/2011

Thank you.

网友答案:

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

网友答案:

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
相关阅读:
Top