sql server 删除所有 视图、存储过程

时间:2024-11-01 12:34:44

删除视图:

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