时间:2021-07-01 10:21:17 帮助过:24人阅读
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中测试通过