/* ------------------------ My Meta Content Here SEO ------------------------ */

Pages

Main Menu




Wednesday, May 21, 2014

Deleting whole data from database using sql server query

--***************  DELETE ALL DATA FROM DATABASE  ***************--

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

EXEC sp_MSForEachTable ' 
IF OBJECTPROPERTY(object_id(''?''), ''TableHasIdentity'') = 1 
DBCC CHECKIDENT (''?'', RESEED, 0) 

GO
--*********************  End of Query   *********************--

No comments:

Post a Comment

Recent Posts

My Blog List