Link to home
Start Free TrialLog in
Avatar of emi_sastra
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.
ASKER CERTIFIED SOLUTION
Avatar of jogos
jogos
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of emi_sastra
emi_sastra

ASKER

Hi Jogos,

ALTER TABLE TDPOJUALBRGCUSTOMER2012 ADD CONSTRAINT FK_TDPOJUALBRGCUSTOMER2012_Nomor_OA, BarangCode  FOREIGN KEY(Nomor_OA, BarangCode) REFERENCES TDPOJUAL2012(Nomor_OA, BarangCode)

What's wrong with my code ?

TDPOJUALBRGCUSTOMER2012_Nomor_OA, BarangCode.

Should be used what code ?

Thank you.
I also try below :

ALTER TABLE TDPOJUALBRGCUSTOMER2012 ADD CONSTRAINT FK_TDPOJUAL2012_TDPOJUALBRGCUSTOMER2012  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_TDPOJUALBRGCUSTOMER2012'. Could not create constraint. See previous errors.

Thank you.
I get it.

Thank you very much for your help.