emi_sastra
asked on
MULTI COLUMNS FOREIGN KEY
Hi All,
I have two tables :
1. TableA
PurchaseOrderNo
ItemNo
Qty_A
Unit_B
2. TableB
PurchaseOrderNo
ItemNo_A
ItemNo_B
Qty_B
Unit_b
......
How could I set foreign key TableB to TableA for PurchaseOrderNo and ItemNo_A ?
Thank you.
I have two tables :
1. TableA
PurchaseOrderNo
ItemNo
Qty_A
Unit_B
2. TableB
PurchaseOrderNo
ItemNo_A
ItemNo_B
Qty_B
Unit_b
......
How could I set foreign key TableB to TableA for PurchaseOrderNo and ItemNo_A ?
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I also try below :
ALTER TABLE TDPOJUALBRGCUSTOMER2012 ADD CONSTRAINT FK_TDPOJUAL2012_TDPOJUALBR GCUSTOMER2 012 FOREIGN KEY(Nomor_OA, BarangCode) REFERENCES TDPOJUAL2012(Nomor_OA, BarangCode)
Exception :
There are no primary or candidate keys in the referenced table 'TDPOJUAL2012' that match the referencing column list in the foreign key 'FK_TDPOJUAL2012_TDPOJUALB RGCUSTOMER 2012'. Could not create constraint. See previous errors.
Thank you.
ALTER TABLE TDPOJUALBRGCUSTOMER2012 ADD CONSTRAINT FK_TDPOJUAL2012_TDPOJUALBR
Exception :
There are no primary or candidate keys in the referenced table 'TDPOJUAL2012' that match the referencing column list in the foreign key 'FK_TDPOJUAL2012_TDPOJUALB
Thank you.
ASKER
I get it.
Thank you very much for your help.
Thank you very much for your help.
ASKER
ALTER TABLE TDPOJUALBRGCUSTOMER2012 ADD CONSTRAINT FK_TDPOJUALBRGCUSTOMER2012
What's wrong with my code ?
TDPOJUALBRGCUSTOMER2012_No
Should be used what code ?
Thank you.