Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

The DELETE statement conflicted with the REFERENCE constraint....

Posted on 2011-02-27
3
Medium Priority
?
804 Views
Last Modified: 2012-05-11
Ran the command: DELETE FROM [dbo].[USERS]

Got the result:
Msg 547, Level 16, State 0, Line 2
The DELETE statement conflicted with the REFERENCE constraint "FK__Institute__cd_ca__541767F8". The conflict occurred in database "Nova", table "dbo.Institute", column 'cd_userlist'.
The statement has been terminated.


How can I fix this? I need to delete the data inside the table USERS.

0
Comment
Question by:John86a
3 Comments
 
LVL 15

Accepted Solution

by:
derekkromm earned 2000 total points
ID: 34993871
For every user you want to delete from dbo.Users, you'll have to delete any rows in dbo.Institute where it is referenced in column cd_userlist

delete from dbo.Institute where cd_userlist in (select <id> from dbo.users)
delete from dbo.Users
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 34993886
there is referential integrity between the users table and the institute table

such that a user identified on the institute table must exist on the user table....

you need to resolve what you will do with the institute table rows for the users that you intend to delete first....

this type of constraint in "general" implies that it was not considered a "valid business process" to allow users once established to be removed... (there are lots of legal requirements in many jurisdictions which mean it becomes difficult to allow data to be removed , are you certain you are required/allowed to remove your user data?)  you need to check with your business analysts as to what steps should be taken.

0
 

Author Closing Comment

by:John86a
ID: 34993898
Great, thanks!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question