首頁  >  文章  >  資料庫  >  批量更新SQL Server数据库的用户视图

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

WBOY
WBOY原創
2016-06-07 15:00:11973瀏覽

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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn