SQL Server. Viewing the name in the definition differs from the actual name of the view.

I am facing a strange problem in SQL server. I have a view in the db named "SPH_F2V_VEB_FIN-04-GLA-07 - inverted and canceled GL publications", but when running the next query, I got a definition with a changed name.

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

      

Output:

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

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

      

If you noticed the name changed to "SPH_F2V_VEB_FIN-04-GLA-07 - inverted and canceled GL publications", changing "and" to "&" , At first it looked like a sql conversion problem or something related to "and" , but i tried multiple views with and and "&" , they seemed to work as expected.

So, any chance how this could happen? I am even quite skeptical about how the database allows this. Any idea would be deeply appreciated!

+3


source to share


1 answer


This can happen if you use sp_rename

to rename a view.

Your best bet is to drop and create it to rename it.



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

+5


source







All Articles