//declare a variable to store procedure namedeclare @name varchar (100)//declare cursor variable to get output from cursordeclare @cur cursor set @cur = cursor for select [name] from sys.objects where type = 'p'//open cursor and fetch the value then drop the procedureopen @curfetch next from @cur into @namewhile @@FETCH_STATUS = 0 begin exec('drop proc '+ @name) fetch next from @cur into @nameendclose @cur deallocate @cur
//same as deleting stored procedure we can delete tables.//declare a variable to table namedeclare @tbl varchar (100)//declare cursor variable to get output from cursordeclare @tabcur cursorset @tabcur = CURSOR FORselect [name] from sys.tables//open cursor and fetch the value then drop the tableopen @tabcurfetch next from @tabcur into @tblwhile @@FETCH_STATUS = 0begin fetch next from @tabcur into @tbl exec('drop table '+ @tbl)endclose @tabcurdeallocate @tabcur