删除视图:


use 数据库名
declare mycur cursor local for select [name] from dbo.sysobjects where xtype='V'  --声明游标
declare @name varchar(100)
 
OPEN mycur    --打开游标
 
FETCH NEXT from mycur into @name
 
WHILE @@FETCH_STATUS = 0 
 
BEGIN
exec('drop VIEW ' + @name)
FETCH NEXT from mycur into @name   --逐条读取
END
 
CLOSE mycur   --关闭游标

 

删除存储过程:


use 数据库名
declare mycur cursor local for select [name] from dbo.sysobjects where xtype='P'
declare @name varchar(100)
 
OPEN mycur
 
FETCH NEXT from mycur into @name
 
WHILE @@FETCH_STATUS = 0 
 
BEGIN
exec('drop PROCEDURE ' + @name)
FETCH NEXT from mycur into @name
END
 
CLOSE mycur

posted on 2015-10-23 11:25  Herf  阅读(3763)  评论(0编辑  收藏  举报