您现在的位置是: 首页 > 后端开发 SqlServer 刷新所有视图

SqlServer 刷新所有视图

2020-05-20 后端开发 2081人已围观 3951次浏览

简介SqlServer 刷新所有视图

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE procedure [dbo].[RefreshAllView]
as
begin
declare @ViewName varchar(250)
declare #views cursor for select name from sysobjects
where objectproperty(id,N’IsView’)=1
and objectproperty(id,N’IsSchemaBound’)=0 and uid=1 order by name
open #views
fetch next from #views into @viewname
while @@fetch_status=0
begin
begin try
exec sp_refreshview @viewname –更新视图
print ’更新成功: ’+ @viewname
end try
begin catch
print ’更新出错: ’+ @viewname + ’ ’ + ERROR_MESSAGE()
end catch
fetch next from #views into @viewname
end
close #views
deallocate #views
end
GO

 

很赞哦! (0)

站长推荐

站点信息

  • 网站地图