SqlServer刷新所有视图

CREATE PROCEDURE RefreshAllView AS
DECLARE MyCursor CURSOR
FOR select Name from dbo.sysobjects where OBJECTPROPERTY(id, N‘IsView‘) = 1 and (not name in (‘sysconstraints‘,‘syssegments‘))
 
DECLARE @name varchar(40)
OPEN MyCursor
 
FETCH NEXT FROM MyCursor INTO @name
WHILE (@@fetch_status <> -1)
BEGIN
 IF (@@fetch_status <> -2)
 begin
 exec sp_refreshview @name
 end
 FETCH NEXT FROM MyCursor INTO @name
END
 
CLOSE MyCursor
DEALLOCATE MyCursor

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。