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.
Author |
Topic |
sparrow37
Posting Yak Master
148 Posts |
Posted - 2011-04-13 : 03:28:20
|
Hi all:I have created a relation in my tables in visual studio 2010 database project and I am getting this error:Error SQL04111: The referenced table '[dbo].[tblAccount]' 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.Here is the foreign key:ALTER TABLE [dbo].[tblDispute] ADD CONSTRAINT [FK_AccountNo] FOREIGN KEY (AccountNo) REFERENCES tblAccount ([Account No]) ON DELETE NO ACTION ON UPDATE CASCADE;How can I fix it ? |
|
Devart
Posting Yak Master
102 Posts |
Posted - 2011-04-13 : 03:52:36
|
Hello,You must create primary or unique key on column [Account No] in parent table before creating foreign key.Best Regards,Devart,SQL Server Tools:dbForge Data StudiodbForge Schema ComparedbForge Data ComparedbForge SQL Complete |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-04-13 : 03:54:06
|
What is the primary key in the table tblAccount?[Account No] should be the primary key in this case... No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-04-13 : 03:54:44
|
too slow... No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
sparrow37
Posting Yak Master
148 Posts |
Posted - 2011-04-13 : 03:57:31
|
account table has composite key consititing of registryid and account no |
|
|
sparrow37
Posting Yak Master
148 Posts |
Posted - 2011-04-13 : 04:07:16
|
Ok, I have fixed the issue by adding composite primary key of account table as foreign key in my table. Before, I was using one of the columns as foreign key. |
|
|
Devart
Posting Yak Master
102 Posts |
Posted - 2011-04-13 : 04:11:44
|
Columns in the Foreign Key and Primary(Unique) Key must be equal.Devart,SQL Server Tools:dbForge Data StudiodbForge Schema ComparedbForge Data ComparedbForge SQL Complete |
|
|
|
|
|