Solved

MULTI COLUMNS FOREIGN KEY

Posted on 2012-03-09
4
274 Views
Last Modified: 2012-03-10
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.
0
Comment
Question by:emi_sastra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 25

Accepted Solution

by:
jogos earned 500 total points
ID: 37704788
ALTER TABLE tableb
ADD CONSTRAINT FK_tableb_tablea FOREIGN KEY (PurchaseOrderNo, ItemNo_A)
    REFERENCES tableA (PurchaseOrderNo, ItemNo_A) ;
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 37704833
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.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 37704840
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.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 37704867
I get it.

Thank you very much for your help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question