Database table design vs. ease of use.

Posted by Gastoni on Stack Overflow See other posts from Stack Overflow or by Gastoni
Published on 2010-03-29T21:21:43Z Indexed on 2010/03/29 21:23 UTC
Read the original article Hit count: 231

Filed under:

I have a table with 3 fields: color, fruit, date. I can pick 1 fruit and 1 color, but I can do this only once each day.

examples:

  1. red, apple, monday
  2. red, mango, monday
  3. blue, apple, monday
  4. blue, mango, monday
  5. red, apple, tuesday

The two ways in which I could build the table are:

1.- To have color, fruit and date be a composite primary key (PK). This makes it easy to insert data into the table because all the validation needed is done by the database.

  • PK color
  • PK fruit
  • PK date

2.- Have and id column set as PK and then all the other fields. Many say thats the way it should be, because composite PKs are evil. For example, CakePHP does no support them.

  • PK id
  • color
  • fruit
  • date

Both have advantages. Which would be the 'better' approach?

© Stack Overflow or respective owner

Related posts about database-design