刷新SqlServer所有视图【存储过程】

摘自:http://www.cnblogs.com/yashen/archive/2004/12/23/81000.html

CREATE PROCEDURE RefreshAllView AS
DECLARE MyCursor CURSOR
FOR select Name from dbo.sysobjects where  OBJECTPROPERTY(id, N'IsView') = 1 and (not name in ('sysconstraints','syssegments'))

DECLARE @name varchar(40)
OPEN MyCursor

FETCH NEXT FROM MyCursor INTO @name
WHILE (@@fetch_status <> -1)
BEGIN
    IF (@@fetch_status <> -2)
    begin
     exec sp_refreshview @name
             end
    FETCH NEXT FROM MyCursor INTO @name
END

CLOSE MyCursor
DEALLOCATE MyCursor

  

posted @ 2015-01-05 14:55  Jaryleely  阅读(393)  评论(0编辑  收藏  举报
TOP
学习,一直学习,就这样下去。。。