Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Create table

Author  Topic 

Kurmanc
Yak Posting Veteran

92 Posts

Posted - 2011-08-16 : 10:17:03
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?

Kurmanc
Yak Posting Veteran

92 Posts

Posted - 2011-08-16 : 10:43:37
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
   

- Advertisement -