Categories
Sql Server

How To Delete All Rows From Table In SQL Server

How To Delete All Rows From Table In SQL Server

Hi guys, in this tutorial i will let you know How To Delete All Rows From Table In SQL Server.If you are willing to delete all rows from your table in one go, and you want that transaction must be logged.

Solution:

Delete  FROM TABLE Where PRIMARY_KEY_ is Not NULL

Here primary key stand for your table primary key, this solution only works.If you have primary key in your table.

If you have Set referential integrity:

EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable 'DELETE FROM ?'
GO
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO