About
Pricing
Community
Teams
Start Free Trial
Log in
emi_sastra
asked on
3/9/2012
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.
Microsoft SQL Server 2005
4
1
Last Comment
emi_sastra
8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
jogos
3/10/2012
THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
emi_sastra
3/10/2012
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_No
mor_OA, BarangCode.
Should be used what code ?
Thank you.
emi_sastra
3/10/2012
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.
emi_sastra
3/10/2012
ASKER
I get it.
Thank you very much for your help.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ALTER TABLE TDPOJUALBRGCUSTOMER2012 ADD CONSTRAINT FK_TDPOJUALBRGCUSTOMER2012
What's wrong with my code ?
TDPOJUALBRGCUSTOMER2012_No
Should be used what code ?
Thank you.