sql server 刪除所有 檢視、儲存過程
阿新 • • 發佈:2018-12-06
--刪除檢視: 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 --關閉遊標 --刪除儲存過程: 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