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
 Some questions about foreign table PK uniqueness

Author  Topic 

lucky7456969
Starting Member

6 Posts

Posted - 2015-02-20 : 05:01:47
1) I have declared IssueProgress to have 2 primary keys
That should do the trick of declaring a composite candidate keys
of Progress_ID and ItemNo

2) I don't want to have the ItemNo to be unique, since it is not :)

3) So how do I make this schema compile?
Thanks
Jack


Msg 1776, Level 16, State 0, Line 41
There are no primary or candidate keys in the referenced table 'IssueProgress' that match the referencing column list in the foreign key 'FK_IssueLog'.

CREATE TABLE IssueProgress (
Progress_ID int NOT NULL IDENTITY,
ItemNo int NOT NULL,
ProgressDate date NOT NULL,
ActionDesc text NOT NULL,
CONSTRAINT PK_IssueProgress PRIMARY KEY NONCLUSTERED ([Progress_ID], [ItemNo]),
UNIQUE (Progress_ID)
);


CREATE TABLE IssueLog (
ItemNo int NOT NULL IDENTITY PRIMARY KEY,
ProjectCode int NOT NULL,
RespRaisedDate date NOT NULL,
Lname varchar(255) NOT NULL,
Fname varchar(255) NOT NULL,
MobileNum varchar(15) DEFAULT NULL,
Email varchar(255) DEFAULT NULL,
RespDesc text NOT NULL,
SupportDoc image,
Resp_Cat_ID int NOT NULL DEFAULT '1',
Personnel_ID int NOT NULL DEFAULT '1',
Ori_Target_Finish_Date date DEFAULT NULL,
Rev_Target_Finish_Date date DEFAULT NULL,
Actual_Finish_Date date DEFAULT NULL,
Approval_Date date DEFAULT NULL,
UNIQUE (ItemNo),
CONSTRAINT FK_IssueLog FOREIGN KEY (ItemNo)
REFERENCES IssueProgress (ItemNo)
ON UPDATE CASCADE
ON DELETE CASCADE
);

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-02-20 : 09:35:43
you need to have a key on the primary table on the ItemNo column
Go to Top of Page
   

- Advertisement -