SQL Server Tips

02 Aug 2013    by: Sameer Das

REMOVE ALL TABLES

EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"

REMOVE ALL USER-DEFINED STORED PROCEDURES

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

REMOVE ALL VIEWS

Declare @viewName varchar(500)
Declare cur Cursor For Select [name] From sys.objects where type = 'v'
Open cur
Fetch Next From cur Into @viewName
While @@fetch_status = 0
Begin
 Exec('drop view ' + @viewName)
 Fetch Next From cur Into @viewName
End
Close cur
Deallocate cur
Tags: