Referential integrity on two fields

  • Thread starter Thread starter Alejandro
  • Start date Start date
A

Alejandro

I seem not to be able to create a relationship between two tables based on
two fields and enforce referential integrity. Is there a way to create this?
The linked fields in both tables must be fields named IDproduct and IDtype
since the product number is not unique, the combination however is.

Please advise.
 
You are having difficulties in creating a relationship between 2 tables,
based on the combination of two fields - IDproduct and IDtype.

1. In one of the tables, create a unique, required, non-null index on the 2
fields together. In table design view, you can do this in the Indexes dialog
(View menu), or you can simply select both the fields (assuming they are
together) and make it the primary key.

2. In the other table, make sure that BOTH fields match exactly on both type
and size. For exmaple, if IDproduct is a Text field, size 50, then the
matching field in the other table must also be Text (50). If IDtype is a
Number field of size Long Integer, then the matching field in the other
table must be a Number (Long Integer). Consider setting the Required
property to Yes for both fields in the foreign table as well.

3. Check the data in the tables. The can be no conbination in one table that
does not exist in the other. Also, there cannot be partial matches (i.e.
where one field matches, and the other is Null in the foreign table).

4. Open the Relationships window (Tools menu).
Drag IdProduct from one table to the other.
When the dialog pops up, enter the 2nd field in both tables as well.
Check the Relational Integrity box.
When you Ok this dialog, you should see 2 lines joining the 2 tables.
 
Back
Top