伯乐共勉

讨论。NET专区
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

更新所有的视图

Posted on 2005-06-01 18:04  伯乐共勉  阅读(835)  评论(0编辑  收藏  举报

create procedure sp_rebuildallview
as
begin

declare @mytext varchar(8000)
declare @id int
declare mycursor cursor for

select c.text from dbo.syscomments c,
 dbo.sysobjects o     where o.id = c.id
and o.type = 'v'
order by c.number, c.colid

open mycursor
fetch next from mycursor into @mytext
while @@fetch_status =0
begin
  set @id = patindex('%create%', @mytext)
 
  set @mytext = stuff(@mytext, @id, 6, 'Alter')
  print @mytext
  exec(@mytext)
  fetch next from mycursor into @mytext
end
close mycursor
deallocate mycursor
end