views:

96

answers:

0

Hi,

I have not very big db. I am using auto increment primary keys and in my case there is no problem with that. GUID is not necessary.

I have a table containing this fields:

  1. from_destination
  2. to_testination
  3. shipper
  4. quantity

Where the fields 1,2,3 needs to be unique. Also I have second table that for the fields 1,2,3 stores bought quantities per day One to many.

  1. from_destination
  2. to_destination
  3. shipper
  4. date
  5. reserved_quantity

case 1 Is it better to make fields 1,2,3 as primary complex key in the first table and the same fields in the second table to be foreign key

First table

from_destination |
to_destination | primary
shipper |
quaitity

Second table
second_id - autoincrement primary
from_destination |
to_destination | foreign key
shipper |
date
reserved_quantity

Case 2
or just to add auto increment filed in the first table and make fields 1,2,3 unique. In the second table there will be one ingeger foreign key pointing to the first table, and one auto increment key for the table.

First table
first_id - autoincrement primary
from_destination |
to_destination | unique
shipper |
quaitity

Second table
second_id - autoincrement primary
first_id - forein
date
reserved_quantity

If so why we need complex keys, when we can have one field auto increment or GUID and all other fields that are candidates for complex key to be unique.

Regards