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

相关文章: