SQL Server 视图在更改基础依赖项后显示过时/错误的数据 [英] SQL Server View showing outdated / wrong data after changing underlying dependencies

查看:24
本文介绍了SQL Server 视图在更改基础依赖项后显示过时/错误的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个视图(称为 X),它是由其他 2 个视图(称为 Y 和 Z)调用的基本视图.

We have a View (call it X) that is the base view called by 2 other views(call them Y and Z).

今天我们对视图 X 进行了更改,之后视图 Y 和 Z 开始带回不正确的数据.当我们在 Management Studio 中运行 SELECT * FROM Y(这正是在代码中调用视图的方式)时,它会取回不正确的数据.然而,当我们运行视图包含它的实际 SQL 时,它是好的.我们尝试了很多方法,直到一位同事建议添加一个空间来查看 X 和 Z,然后运行 ​​Alter,这奏效了.一切恢复正常并运行良好.

Today we made a change to view X, after that view Y and Z started bringing back data that was incorrect. When we were in Management Studio and ran SELECT * FROM Y(which is exactly how the view is called in code) it would get back data that was incorrect. However, when we ran the actual SQL that the view contained it was fine. We tried a number of things until a colleague suggested adding a space to view X and Z and then running Alter, which worked. Everything returned to normal and ran fine.

我的问题是:MSSQL 是否缓存其视图?如果是这样,您如何强制它们不或强制它们重新编译?

My question is: Does MSSQL cache its views? and if so how do you force them not to OR force them to re-compile?

此外,任何关于此的额外阅读都会有所帮助.

Also, any additional reading about this would be helpful.

推荐答案

请参阅 sp_refreshview 命令.

更新指定的非架构绑定视图的元数据.视图的持久元数据可能会因更改而过时到视图所依赖的底层对象.

Updates the metadata for the specified non-schema-bound view. Persistent metadata for a view can become outdated because of changes to the underlying objects upon which the view depends.

这篇关于SQL Server 视图在更改基础依赖项后显示过时/错误的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆