Showing posts with label How to Delete all the data from the Database with simple Query- Sql Server. Show all posts
Showing posts with label How to Delete all the data from the Database with simple Query- Sql Server. Show all posts

Tuesday, February 24, 2009

How to Delete all the data from the Database with simple Query- Sql Server

use practice
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable '
IF OBJECTPROPERTY(object_id(”?”), ”TableHasForeignRef”) = 1
DELETE FROM ?
else
TRUNCATE TABLE ?
'
GO
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO