Skip to content
Advertisement

In SQL, how to remove from only 1 table from 2 related tables

I have related tables in SQL (one to many). One is employees table and the other is the record table for day offs, When i want to delete one employee I get the below error in C#:

SqlException: The DELETE statement conflicted with the REFERENCE constraint “FK_Izin_Personel”. The conflict occurred in database “Inotra”, table “dbo.Izin”, column ‘personelid’.
The statement has been terminated.

I tried changing insert and update actions to cascade and that worked for other tables, but it also deletes from both tables when I delete from one.

So my question is: How can I remove from only one of the two related tables, so that the records of other table remain unchanged?

Advertisement

Answer

Relationships ensure data integrity, without them, data may be incomplete or incorrect. In your case you need to remove the relationship between the tables(“FK_Izin_Personel”), then there will be no error.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement