欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

批量更新SQL Server数据库的用户视图

程序员文章站 2022-04-22 11:55:33
...

DECLARE @vName sysname DECLARE refresh_cursor CURSOR FOR SELECT Name from sysobjects WHERE xtype = 'V' order by crdate FOR READ ONLY OPEN refresh_cursor FETCH NEXT FROM refresh_cursor INTO @vName WHILE @@FETCH_STATUS = 0 BEGIN --刷新指定视

DECLARE @vName sysname

DECLARE refresh_cursor CURSOR FOR
SELECT Name from sysobjects WHERE xtype = 'V' order by crdate
FOR READ ONLY
OPEN refresh_cursor

FETCH NEXT FROM refresh_cursor
INTO @vName
WHILE @@FETCH_STATUS = 0
BEGIN
--刷新指定视图的元数据。由于视图所依赖的基础对象发生更改,视图的持久元数据会过期。
exec sp_refreshview @vName
PRINT '视图' + @vName + '已更新'
FETCH NEXT FROM refresh_cursor
INTO @vName
END
CLOSE refresh_cursor
DEALLOCATE refresh_cursor

以上数据库脚本在SQL Server 2005中测试通过