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 2005 Forums
 Transact-SQL (2005)
 Relationshp creation fails

Author  Topic 

missMac
Posting Yak Master

124 Posts

Posted - 2008-11-24 : 20:08:05
Hello Guys,
Am trying to create a relationship bw two tables. Columns username vs username

But it fails, error message is

'Users' table saved successfully
'credits' table
- Unable to create relationship 'FK_credits_Users1'.
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_credits_Users1". The conflict occurred in database "mydatabase", table "dbo.Users", column 'Username'.


What is wrong here and how do i fix it.

The relationship existed in the old table, i just imported data to the new table, so i believe the column values are identical

MM




snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2008-11-24 : 21:54:54
It means you have a Username value in the credits table that does not exist in the Username column in Users. I'm guessing a little because you did not give the code that you are running.

You can check by running a query to see if there are values missing, something like:

SELECT * FROM credits
WHERE NOT EXISTS (SELECT * FROM users WHERE users.Username = credits.Username)
Go to Top of Page

missMac
Posting Yak Master

124 Posts

Posted - 2008-11-25 : 06:19:22
thank you very much

MM


Go to Top of Page
   

- Advertisement -