摘自: http://www.cnblogs.com/yashen/archive/2004/12/23/81000.HTML我们在使用sqlServer时经常遇到这种情况,当修改某个表的结构后,相关的视图就不对了而导致程序错误,因此就有个下面这个存储过程。CREATE PROCEDURE RefreshAllVIEw ASDECLARE MyCursor CURSORFOR select name from dbo.sysobjects where OBJECTPROPERTY(ID,N'IsVIEw') = 1 and (not name in ('sysconstraints','syssegments'))DECLARE @name varchar(40)OPEN MyCursorFETCH NEXT FROM MyCursor INTO @nameWHILE (@@fetch_status <> -1)BEGIN IF (@@fetch_status <> -2) begin exec sp_refreshvIEw @name end FETCH NEXT FROM MyCursor INTO @nameENDCLOSE MyCursorDEALLOCATE MyCursor
执行存储过程:
Exec RefreshAllVIEw
------------------------------
把以上代码做一个整合
if exists(SELECT * FROM sysobjects where ID = OBJECT_ID('RefreshAllVIEw') and xtype='p' ) drop proc RefreshAllVIEwgoCREATE PROCEDURE RefreshAllVIEw ASDECLARE MyCursor CURSORFOR select name from dbo.sysobjects where OBJECTPROPERTY(ID,'syssegments'))DECLARE @name varchar(40)OPEN MyCursorFETCH NEXT FROM MyCursor INTO @nameWHILE (@@fetch_status <> -1)BEGIN IF (@@fetch_status <> -2) begin exec sp_refreshvIEw @name end FETCH NEXT FROM MyCursor INTO @nameENDCLOSE MyCursorDEALLOCATE MyCursorgoExec RefreshAllVIEw总结
以上是内存溢出为你收集整理的刷新SqlServer所有视图元数据的存储过程全部内容,希望文章能够帮你解决刷新SqlServer所有视图元数据的存储过程所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)