SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Create table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Kurmanc
Yak Posting Veteran

92 Posts

Posted - 08/16/2011 :  10:17:03  Show Profile  Reply with Quote
Hi,

I have a table let say it is called Table_1. PK for this table is composite; a_ID and b_ID.

When I create the following table I get an error:

There are no primary or candidate keys in the referenced table 'Table_1' that match the referencing column list in the foreign key FK_SomeTable...


CREATE TABLE SomeTable
(
a_ID INT NOT NULL,
b_ID INT NOT NULL,
c_ID INT NOT NULL,
Name VARCHAR(50)
PRIMARY KEY(a_ID, b_ID, c_ID)
FOREIGN KEY (a_ID) REFERENCES Table_1 (a_Id) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (b_ID) REFERENCES Table_1 (b_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (c_ID) REFERENCES Table_2 (InstrumentId) ON DELETE NO ACTION ON UPDATE NO ACTION
)

How do I get around this?

Edited by - Kurmanc on 08/16/2011 10:20:11

Kurmanc
Yak Posting Veteran

92 Posts

Posted - 08/16/2011 :  10:43:37  Show Profile  Reply with Quote
Don't bother. I fixed it...

OLD:
FOREIGN KEY (a_ID) REFERENCES Table_1 (a_Id) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (b_ID) REFERENCES Table_1 (b_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,

NEW:
FOREIGN KEY (a_ID, b_ID) REFERENCES Table_1
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.22 seconds. Powered By: Snitz Forums 2000