SQL Server - 定义中的 View 名称与实际 View 名称不同

标签 sql sql-server sql-server-2014

我在 SQL Server 中遇到了一个奇怪的问题。我在数据库中有一个名为“SPH_F2V_VEB_FIN-04-GLA-07 - Reversed and Canceled GL Postings”的 View ,但是当运行以下查询时,我得到了一个名称已更改的定义。

SELECT object_definition (OBJECT_ID(N'dbo.SPH_F2V_VEB_FIN-04-GLA-07 - Reversed and Cancelled GL Postings'))

输出:

CREATE VIEW [dbo].[SPH_F2V_VEB_FIN-04-GLA-07 - Reversed & Cancelled GL Postings] AS

SELECT 
    --GL1.[Business Unit],
    GL1.[Company Code],
    GL1.Description,
....

如果您注意到,名称已更改为“SPH_F2V_VEB_FIN-04-GLA-07 - 已撤销和已取消的总帐过账”,将“和”更改为“&”。起初它似乎是一个sql转换问题或与“and”相关的东西,但我尝试了几个带有“and”“&”的 View >,它们似乎按预期工作。

那么,这怎么可能发生?我什至对 DB 如何允许这样做持怀疑态度。任何想法将不胜感激!!

最佳答案

如果您使用 sp_rename 就会发生这种情况重命名 View 。

最好先drop再创建再重命名。

Renaming a stored procedure, function, view, or trigger will not change the name of the corresponding object name in the definition column of the sys.sql_modules catalog view. Therefore, we recommend that sp_rename not be used to rename these object types. Instead, drop and re-create the object with its new name.

关于SQL Server - 定义中的 View 名称与实际 View 名称不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43558889/

相关文章:

sql - 插入时将数字转换为数据类型数字的算术溢出错误

java - 如何在不设置环境变量的情况下使用PowerShell脚本在Tomcat中绑定(bind)JDK

sql - Microsoft t sql 如何在用户定义的函数中声明临时变量?

sql-server - SQL Server 数据补丁,用于将中间的 2 个双引号替换为单个双引号

sql - PostgreSQL 标准

SQL Server - 获取与 where 子句相反的内容

sql - 在 SQLite 中查找与 GROUP BY 结果 HAVING count > 1 匹配的所有记录

sql - Postgres 列不存在

sql - 拥有条款面临的问题

sql - 如何在 SQL 中查找去年的同一个工作日?