FreeriderUK
Well-known member
I found the following query and tried to execute in Management Studio, but has a problem with one of the tables:
I want to be able to delete all the data in all tables within my program.
I thought this would work, since it disables the constraints.
Why doesn't it work?
Is there a better way?
VB.NET:
-- disable referential integrity
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable 'TRUNCATE TABLE ?'
GO
-- enable referential integrity again
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO
Cannot truncate table 'dbo.Jobs' because it is being referenced by a FOREIGN KEY constraint.
I want to be able to delete all the data in all tables within my program.
I thought this would work, since it disables the constraints.
Why doesn't it work?
Is there a better way?