Hi all,
I'm creating a database and I'm having trouble with composite primary keys. I've read on a few forums that good databases should use composite primary keys over say an autonumber. And it does neaten up the database a bit, i.e. if a record is deleted there is no messy skipped numbers in the primary key (ID field). A simple example of my problem from my database is when I have two tables one that contains a list of raw materials and its relationship with the bill of materials (materials matched with products, a many-many table).
tbl_Raw_Materials
Material_Category
Material_Name (Primary Key)
Material_Colour (Primary Key)
tbl_Bill_of_Materials
Product_Code (Primary Key)
Material_Name (Primary Key)
Material_Colour (Primary Key)
Material_Length (Primary Key)
Material_Quantity
I have chosen these composite keys such that each record will contain a unique primary key. However, I have yet to work out how to induce referential integrity in these instances due the primary keys, and not recieve the message,
"No unique index found for the referenced field of the primary table."
Is there a way to achieve referential integrity while using composite primary keys? My main reason is to insure when a material is deleted from the database that it follows through to the bill of materials.
Cheers,
Raymas
I'm creating a database and I'm having trouble with composite primary keys. I've read on a few forums that good databases should use composite primary keys over say an autonumber. And it does neaten up the database a bit, i.e. if a record is deleted there is no messy skipped numbers in the primary key (ID field). A simple example of my problem from my database is when I have two tables one that contains a list of raw materials and its relationship with the bill of materials (materials matched with products, a many-many table).
tbl_Raw_Materials
Material_Category
Material_Name (Primary Key)
Material_Colour (Primary Key)
tbl_Bill_of_Materials
Product_Code (Primary Key)
Material_Name (Primary Key)
Material_Colour (Primary Key)
Material_Length (Primary Key)
Material_Quantity
I have chosen these composite keys such that each record will contain a unique primary key. However, I have yet to work out how to induce referential integrity in these instances due the primary keys, and not recieve the message,
"No unique index found for the referenced field of the primary table."
Is there a way to achieve referential integrity while using composite primary keys? My main reason is to insure when a material is deleted from the database that it follows through to the bill of materials.
Cheers,
Raymas