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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 foreign key error

Author  Topic 

joemama
Posting Yak Master

113 Posts

Posted - 2005-04-03 : 20:43:21
in database designer i am trying to create a foreign key from userID in Users to UserID in Newsletter and i get this error...

'Users' table saved successfully
'Newsletter' table
- Unable to create relationship 'FK_Newsletter_Users'.
ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint 'FK_Newsletter_Users'. The conflict occurred in database 'rsensations', table 'Users', column 'UserID'.

any clue?

nr
SQLTeam MVY

12543 Posts

Posted - 2005-04-03 : 20:47:11
You have data in the table which doesn't have corresponding data in the referenced table.
try

select distinct n.UserID
from Newsletter n
left join Users u
on u.UserID = n.UserID
where u.UserID is null

That will give all the entries that violate the fk.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

joemama
Posting Yak Master

113 Posts

Posted - 2005-04-03 : 23:46:59
that did it...thannks!

quote:
Originally posted by nr

You have data in the table which doesn't have corresponding data in the referenced table.
try

select distinct n.UserID
from Newsletter n
left join Users u
on u.UserID = n.UserID
where u.UserID is null

That will give all the entries that violate the fk.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Go to Top of Page
   

- Advertisement -