sql server 刪除全部 視圖、存儲過程

 


刪除視圖:數據庫


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   --關閉遊標object

 

刪除存儲過程:select


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 數據

相關文章
相關標籤/搜索