导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

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

longsql 2007-12-21 05:39:04
请问各位老大,我想删掉一个数据库的所有视图,怎么写语句呢,谢谢各位!
...全文
65 点赞 收藏 2
写回复
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
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告