Drop all tables n stored procedure in Sql Server

Feb 18, 2019 BY xtreme

Can Remove all Tables and Store Procedure for a Database at once.


Drop all user defined tables


EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"




Drop all user defined Stored Procedures


Declare @pName varchar(500) 
Declare sqlcur Cursor For Select [name] From sys.objects where type = 'p' 
Open sqlcur 
   Fetch Next From sqlcur Into @pName 
   While @@fetch_status = 0 
   Begin 
               Exec('drop procedure ' + @pName ) 
       Fetch Next From sqlcur Into @pName 
   End
Close sqlcur 
Deallocate sqlcur 




Related