Reputation: 1143
Is there any way to delete all records from all tables of a database yet keeping all the constraints.
I used a script available on net but it fails where foreign keys are defined.
Upvotes: 1
Views: 1046
Reputation: 36
CREATE PROCEDURE sp_EmplyAllTable
AS
EXEC sp_MSForEachTable ‘ALTER TABLE ? NOCHECK CONSTRAINT ALL’
EXEC sp_MSForEachTable ‘DELETE FROM ?’
EXEC sp_MSForEachTable ‘ALTER TABLE ? CHECK CONSTRAINT ALL’
GO
Upvotes: 2