--上面写错了,不应该加括号--下面是一次重新编译所有视图 declare @s nvarchar(4000) declare tb cursor local for select 'sp_refreshview '''+name+'''' from sysobjects where xtype='V' and status>=0 open tb fetch tb into @s while @@fetch_status=0 begin exec(@s) fetch tb into @s end close tb deallocate tb
DECLARE cur_view cursor FOR SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWSDECLARE @name varchar(40) OPEN cur_viewFETCH NEXT FROM cur_view into @name WHILE (@@fetch_status <> -1) BEGIN IF (@@fetch_status <> -2) BEGIN exec(' sp_refreshview '+@name) END FETCH NEXT FROM cur_view INTO @name ENDCLOSE cur_view DEALLOCATE cur_view GO
declare @s nvarchar(4000)
declare tb cursor local for
select 'sp_refreshview '''+name+''''
from sysobjects
where xtype='V' and status>=0
open tb
fetch tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch tb into @s
end
close tb
deallocate tb
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWSDECLARE @name varchar(40)
OPEN cur_viewFETCH NEXT FROM cur_view into @name
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
exec(' sp_refreshview '+@name)
END
FETCH NEXT FROM cur_view INTO @name
ENDCLOSE cur_view
DEALLOCATE cur_view
GO