Avatar of yrcdba7
yrcdba7Flag for United States of America asked on

FK reference sql server 2005

expert,

I run one sproc script, it gave me error like
There are no primary or candidate keys in the referenced table 'MUSERS' that match the referencing column list in the foreign key 'FK_US_DUSERS'.

I don't understand what is the meaning for this error? how can I know FK_US_DUSERS in which table? or FK_US_DUSERS in table MUSERS which column as FK in other table?

Please help!
Lynn
Microsoft SQL Server

Avatar of undefined
Last Comment
yrcdba7

8/22/2022 - Mon
HainKurt

you should add parent record first...

for example you add a city to Ontario but you did not define Ontario yet...

so first insert ontario into distinct, then insert Toronto into city table
HainKurt

post your statement, also structure of MUSERS  table...

check the definition of 'FK_US_DUSERS' to understand what you should insert first...
ASKER CERTIFIED SOLUTION
sammySeltzer

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
yrcdba7

I cried to create unique index but it tell me that the index for the FK FK_US_DUSERS in table MUSERS  already created.


Msg 1913, Level 16, State 1, Line 1
The operation failed because an index or statistics with name 'IX_DOCUSERS_NUM' already exists on table 'MUSERS'.

any help?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
yrcdba7

the error is:

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

I already create unique index on MUSERS on FK FK_US_DUSERS. why above errror message came out again.

Please help!!!!!!!!

LYnn
HainKurt

please post the table structure
also find the table where 'FK_US_DUSERS' is defined and post the script/definion of that table

it should be like

CONSTRAINT [FK_US_DUSERS]
FOREIGN KEY ([SOME_COLUMN])
REFERENCES [dbo].[SOME_OTHER_TABLE] ( [SOME_OTHER_COLUMN] )
HainKurt

basically you are trying to insert/delete/update a record in a table where there is FK saying the some columns in that record should exists in some other table

to make this work, the other table should have a index on referenced columns so the lookup can be done... you are missing this index on other table...
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASta

Show structure of MUsers

or
- try to drop index IX_DOCUSERS_NUM
- add primary key to table MUsers
- try add constraint again
- and do it only if you work with development server :)
ASKER
yrcdba7

Thank you, you released my stress.
Thank you so much.

Lynn