如何删掉一个库里的所有视图

longsql 2007-12-21 05:39:04
请问各位老大,我想删掉一个数据库的所有视图,怎么写语句呢,谢谢各位!
...全文
93 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangCK 2007-12-21
  • 打赏
  • 举报
回复
declare @viewname sysname
declare cur cursor for
select name from sysobjects where xtype='V'
open cur
fetch next from cur into @viewname
while @@fetch_status=0
begin
exec ('drop view '+@viewname)
fetch next from cur into @viewname
end
close cur
deallocate cur
tim_spac 2007-12-21
  • 打赏
  • 举报
回复

declare @vw_name varchar(128)
declare @sql varchar(512)

declare cur_views cursor for
select name from dbo.sysobjects where type=N'V' and category=0
open cur_views
fetch next from cur_views into @vw_name
while @@fetch_status!=-1 begin
set @sql = 'drop view '''+@vw_name+''''
exec @sql
fetch next from cur_views into @vw_name
end
close cur_views
deallocate cur_views

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧