"MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxx> wrote on 12/14/2016
11:15:07 AM:
Does the Customer table need to have an index that has Customergroup
as part of the key in order for me to setup a foreign key?
An index is not *required* in order to set up a foreign key
relationship. The constraint for the foreign key relationship carries an
implied index. I may not word this correctly, but, you can certainly add
a unique key constraint to the foreign key column -- which creates an
implied index, too. Here is an example from one of my tables.
Alter Table IM_LIFO_Inventory_Adjustments
Add Constraint IMLFADJT_PK
Primary Key (IMLFADJT_ID);
Label On Constraint IMLFADJT_PK
Is 'IM-LIFO Inventory-Temporary Adjustments-PK';
-------------------------------------------------
Alter Table IM_LIFO_Inventory_Adjustments
Add Constraint IMLFADJT_IM02TID_UK
Unique (IM02T_ID);
Label On Constraint IMLFADJT_IM02TID_UK
Is 'IM-LIFO Inventory-Temporary Adjustments-UK';
-------------------------------------------------
Alter Table IM_LIFO_Inventory_Adjustments
Add Constraint IMLFADJT_IM02TID_FK
Foreign Key (IM02T_ID)
References IM02T (IM02TID)
On Delete Restrict
On Update Restrict;
Label On Constraint IMLFADJT_IM02TID_FK
Is 'IM-LIFO Inventory-Temp Adjustment-IM02T-FK';
Sincerely,
Dave Clark
As an Amazon Associate we earn from qualifying purchases.