刷新SqlServer所有视图元数据的存储过程

刷新SqlServer所有视图元数据的存储过程,第1张

概述摘自: http://www.cnblogs.com/yashen/archive/2004/12/23/81000.html我们在使用SqlServer时经常遇到这种情况,当修改某个表的结构后,相关的视图就不对了而导致程序错误,因此就有个下面这个存储过程。CREATE PROCEDURE RefreshAllView ASDECLARE MyCursor CURSORFOR sele
摘自: 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所有视图元数据的存储过程所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1168662.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存