Geeks With Blogs
Gaurav Taneja Great dreams... never even get out of the box. It takes an uncommon amount of guts to put your dreams on the line, to hold them up and say, "How good or how bad am I?" That's where courage comes in.

Create

Procedure GT_DeleteRecords_AllTables

As

 

/*********************************************************

Stored Procedure: GT_DeleteRecords_AllTables

Do not excute this proc

Purpose: Delete ALL records within ALL the tables in a DB with ease.

Test: Exec GT_DeleteRecords_AllTables**********************************************************/

Set

Exec

nocount on sp_MSForEachTable 'Alter Table ? NoCheck Constraint All'

Exec

sp_MSForEachTable

'

If ObjectProperty(Object_ID(''?''), ''TableHasForeignRef'')=1

Begin

-- Just to know what all table used delete syntax.

Print ''Delete from '' + ''?''

Delete From ?

End

Else

Begin

-- Just to know what all table used Truncate syntax.

Print ''Truncate Table '' + ''?''

Truncate Table ?

End

'

Exec

sp_MSForEachTable 'Alter Table ? Check Constraint All' Posted on Monday, June 29, 2009 5:21 AM SQL SERVER | Back to top


Comments on this post: Truncating All Tables

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Gaurav Taneja | Powered by: GeeksWithBlogs.net