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
go重建当前数据库中的所有视图
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
go重建当前数据库中的所有视图
select * from sys.all_views --得到所有视图名DBCC DBREINDEX ("视图名") --对表或者视图重新生成索引,在一定意义上相当于重建视图
这个
想起很久以前一个issue,
我在重建的时候,
其中有一个视图无法重建,
提示是:
Msg 8197, Level 16, State 8, Procedure sp_refreshview, Line 1
Object 'xxxx' does not exist or is invalid for this operation.
百思不得其解......
这个视图和其它视图是一致的,
只是中间多了一个INNER JOIN 而已.