Wrong object_name and definition relationship in sys.sql_modules and sys.objects

不想你离开。 提交于 2021-01-28 09:35:56

问题


I ran the following query

SELECT sm.object_id,
       v1.object_name,
       o.type,
       o.type_desc,
       sm.definition
FROM sys.sql_modules sm
     CROSS APPLY (VALUES (OBJECT_NAME(sm.object_id))) v1 (object_name)
     JOIN sys.objects o ON sm.object_id = o.object_id;

And there are three objects with a wrong relation between object_name and definition. There is no match, no correspondence between the name and the definition it references.

It looks like this tables didn't track the delete or changes in name and definitions of these three objects.

How can this situation can be given? How can I "update" this tables or fix this properly?


回答1:


This is a side effect of using "sp_rename".
These objects will work fine, but to refresh their definitions you need to recreate them.

From sp_rename documentation:

Renaming a stored procedure, function, view, or trigger will not change the name of the corresponding object either in the definition column of the sys.sql_modules catalog view or obtained using the OBJECT_DEFINITION built-in function. 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.



来源:https://stackoverflow.com/questions/59949317/wrong-object-name-and-definition-relationship-in-sys-sql-modules-and-sys-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!