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
 SQL Server Development (2000)
 conflict in adding foreign key

Author  Topic 

ujjaval
Posting Yak Master

108 Posts

Posted - 2005-12-27 : 21:44:56
I have two tables, TableA and TableB.

TableA has two fields 'id' and 'name'. 'id' is PK.

TableB has two fields 'no' and 'id'. Combination of 'no' and 'id' is PK.

a thirdTable has foreign key constraints on 'id' in TableA.

Now, when I try to add foriegn key constraint at 'id' in TableB, SQL Server gives me error.

I am doing following"

alter table [dbo].[TableB] add constraint [FK_TableB_TableA] foreign key (
[id]
) references [dbo].[TableA](
[id]
)

when i run this, I get following error message:

Server: Msg 547, Level 16, State 1, Line 1
ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint 'FK_PatVisits_Patients'. The conflict occurred in database 'cta', table 'Patients', column 'UnivID'.


Any ideas why this is happening??

thanks in advance.
ujjaval

Kristen
Test

22859 Posts

Posted - 2005-12-28 : 10:51:07
I'm stuck because you've described the tables as TableA and TableB yet the error message refers to the tables, not unreasonably!, by their real names.

Your best bet is to post a script of the DDL for all the tables involved and someone here will take a look and give you some advice.

(Posting DDL is always the best way because us lot can then just run it and try it - rather than trying to imagine and guesstimate what might have gone wrong )

Kristen
Go to Top of Page
   

- Advertisement -