I got error “The DELETE statement conflicted with the REFERENCE constraint”

I tried to truncate a table with foreign keys and got the message:

"Cannot truncate table because it is being referenced by a FOREIGN KEY constraint".

I read a lot of literature about the problem and thought that I found the solution by using delete

DELETE FROM table_name DBCC CHECKIDENT (table_name, RESEED, 0)

But I still got an error message:

"The DELETE statement conflicted with the REFERENCE constraint".

When I try to delete with Microsoft Management Studio and execute the previous query

DELETE FROM table_name DBCC CHECKIDENT (table_name, RESEED, 0)

it doesn't give an error and works properly. I want to delete all information from a table and add new into it, but I don't want to drop and create foreign keys.

48
задан Rob 3 August 2017 в 04:49
поделиться