问题
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