x

Alter Table Conflict

ALTER TABLE EA.TECHNOLOGY_UTILIZATION
ADD CONSTRAINT  TECHUTIL_FK_IT_1 
FOREIGN KEY (INFORMATION_TECHNOLOGY_ID) 
REFERENCES EA.INFORMATION_TECHNOLOGY(INFORMATION_TECHNOLOGY_ID)

go

when I execute this command I get this error

Msg 547, Level 16, State 0, Line 1
The ALTER TABLE statement conflicted 
with the FOREIGN KEY constraint "TECHUTIL_FK_IT". 
The conflict occurred in database 
"test_db", table "EA.INFORMATION_TECHNOLOGY", 
column 'INFORMATION_TECHNOLOGY_ID'.

I thought there is some dependency or exisitng already.. for safe side.. dropped the constraint.. then the error message said

Msg 3728, Level 16, State 1, Line 1
'TECHUTIL_FK_IT' is not a constraint.
Msg 3727, Level 16, State 0, Line 1
Could not drop constraint. See previous errors.

Any insight.. of the issue here?

more ▼

asked Mar 26 '10 at 01:20 PM in Default

Katie 1 gravatar image

Katie 1
1.4k 129 163 202

can you post the full scripted DDL of both tables?
Mar 26 '10 at 02:08 PM Kev Riley ♦♦
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

I think the problem is that there are values in the TECHNOLOGY_UTILIZATIONADD column of INFORMATION_TECHNOLOGY_ID that aren't present in INFORMATION_TECHNOLOGY. Try this query to test:

select  *
from    EA.TECHNOLOGY_UTILIZATIONADD tu
    left join EA.INFORMATION_TECHNOLOGY it on it.INFORMATION_TECHNOLOGY_ID = tu.INFORMATION_TECHNOLOGY_ID
where   it.INFORMATION_TECHNOLOGY_ID is null

That will show you the offending rows. You'll have to fix them before you can add the constraint.

more ▼

answered Mar 26 '10 at 03:34 PM

David Wimbush gravatar image

David Wimbush
4.7k 28 29 31

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1933
x976
x124
x107

asked: Mar 26 '10 at 01:20 PM

Seen: 2154 times

Last Updated: Mar 26 '10 at 01:47 PM