2 Primary Keys

  • Thread starter Thread starter Douglas J. Steele
  • Start date Start date
D

Douglas J. Steele

Just a semantic pont, but, by definition, you can't have 2 primary keys.

Are you asking about having a primary key that has more than one field in
it? In that case, then yes, you can have the same product for multiple
suppliers, but you can't repeat a product for the the same supplier.
 
Hi!

Can someone explain to me what is the purpose of using more the one
primary key in a table?
What will be the result of doing so?

If I have a table of Products which has two primary keys:
1. ProductID
2. SupplierID

If I set the ProductID to be indexed (allow duplicates) and the
SupplierID to be indexed (duplicates are not allowed) does that
mean I could have different products with the same ID, but
not if they are from the same supplier?

What is the advantage of using this method of double primary
key as opposed to using validation rules?


Regards.
 
Hi

following from Doug's post ...
leave the index settings alone ... creating a primary key with two fields
will do the type of "validation" that you want .. .

however be careful if you set the primary key with the fields described you
are in fact saying that supplier A can only EVER buy product A once ...
maybe you need to include a date field in the primary key so that supplier A
can only purchase product A on a single date, but can purchase product A
again later on.

Regards
JulieD
 
Hi there!

In my DB there is a table with double field primary key:
It's primary key is builded from the ReceiptNumber and
the ReceiptSupplier Fields. I thought this is good because
one supplier can't have more than one Receipt with the same
number, but different suppliers can use the same receipt number.

What should I put in the index? After all, I want
to allow duplicates in the receipt numbers
but I only want to allow it if it's for different suppliers.

Amir.
 
As Julie said, you put both fields in the primary key.

When you have the table open in Design mode, highlight both fields, then
click on the "Key" icon to create the primary key.
 
OK, Thank you very much!


Douglas J. Steele said:
As Julie said, you put both fields in the primary key.

When you have the table open in Design mode, highlight both fields, then
click on the "Key" icon to create the primary key.
 
Back
Top