April 15, 2015 at 3:03 am
-4
down vote
favorite
i have table (ClassTab) contains [ClassNum,BranchID,SysNum primary key,StageNum,foregin Key, (BranchID,SysNum and also foregin key )],(StageTab) contain [StageNum,BranchID,SysNum primary Key ,(BranchID,SysNum and also foregin key ) ] , SubjTab contains [SubjNum,,BranchID,SysNum primary key,ClassNum foregin Key,(BranchID,SysNum and also foregin key )],BranchesTab contain(BranchId primary Key ) and SysTab contains [SysNum primary Key ] . i want create relationship betwen tables as i show above but i face error when i make foregin key(ClassNum) in SubjTab it show sql71516 error,and when i make foregin key(StageNum) in ClassTab it show in SubjTab (SQL71516 :: The referenced table '[dbo].[ClassTab]' contains no primary or candidate keys that match the referencing column list in the foreign key. If the referenced column,) it show in ClassTab ((((SQL71516 :: The referenced table '[dbo].[ClassTab]' contains no primary or candidate keys that match the referencing column list in the foreign key. If the referenced column SQL71516 :: The referenced table '[dbo].[StageTab]' contains no primary or candidate keys that match the referencing column list in the foreign key. If the referenced column))) is a computed column, it should be persisted. in SubjTab : CONSTRAINT [pk-SubjTab] PRIMARY KEY CLUSTERED ([SubjNum] ASC),([BranchId] ASC),([SysNum] ASC) CONSTRAINT [Fk-SubjTab-Totable] FOREIGN KEY ([BranchId]) REFERENCES Branches , CONSTRAINT [Fk-SubjTab-Totable1] FOREIGN KEY ([SysNum]) REFERENCES SysTab , CONSTRAINT [Fk-SubjTab-Totable2] FOREIGN KEY ([ClassNum]) REFERENCES ClassTab , the error show beacuse last foregin key (between stars ) in Class Tab : CONSTRAINT [pk-ClassTab] PRIMARY KEY CLUSTERED ([ClassNum] ASC),([BranchId] ASC),([SysNum] ASC) CONSTRAINT [Fk-ClassTab-Totable] FOREIGN KEY ([BranchId]) REFERENCES Branches , CONSTRAINT [Fk-ClassTab-Totable1] FOREIGN KEY ([SysNum]) REFERENCES SysTab , CONSTRAINT [Fk-ClassTab-Totable2] FOREIGN KEY ([StageNum]) REFERENCES StageTab , also in ClassTab show error also sql71516 what is rong , what can i do ?????
April 15, 2015 at 3:05 am
Your question is difficult to read. Can you reformat it to make things clearer?
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
April 15, 2015 at 3:06 am
What's wrong is that the primary key of the table you're referencing is not on the column that you're using in the foreign key. A foreign key requires that the referenced column either has a primary key, unique constraint or unique index.
p.s. In future please break your posts up into paragraphs. That was incredibly hard to read.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply