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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…