我在 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/