Disable foreign key constraint for all tables does not work

I try many commands to disable table restrictions in my database, to truncate all tables, but still now it gives me the same error:

Cannot truncate table '' because the FOREIGN KEY constraint refers to it.

I'll try

EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
EXEC sp_MSforeachtable "TRUNCATE TABLE ?"

And I tried this for every table

ALTER TABLE [Table Name] NOCHECK CONSTRAINT ALL  
truncate table [Table Name]
ALTER TABLE [Table Name] CHECK CONSTRAINT ALL  

and every time I have a previous error message. How can I solve this problem?

+3
source share
2 answers

If you want to truncate the table, you may need to reset the foreign keys and add them back. From here .

" TRUNCATE TABLE , FOREIGN KEY, DELETE WHERE. TRUNCATE TABLE , ."

SO.

+5
+1

Source: https://habr.com/ru/post/1737788/


All Articles