Home  >  Article  >  Database  >  批量更新SQL Server数据库的用户视图

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

WBOY
WBOYOriginal
2016-06-07 15:00:11942browse

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中测试通过

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn