简体   繁体   English

SQL Server 2008孤立存储过程?

[英]SQL Server 2008 Orphaned Stored Procedure?

I am using SQL Server 2008 through SQL Server Management Studio 我正在通过SQL Server Management Studio使用SQL Server 2008

I have never seen this before: 我以前从未见过:

Often, when refactoring a database as I have been doing most of my day, I use the following to find references to columns, tables and other procedures in my existing procedures: 通常,当我一整天都在重构数据库时,我使用以下内容在现有过程中查找对列,表和其他过程的引用:

select *
from sys.sql_modules
where [definition] like '%SomethingImLookingFor%'

This is nothing special, I'm sure lots of database heads have done it before. 这没什么特别的,我敢肯定很多数据库负责人以前都做过。

However, I noticed the results contained a procedure that looks to have been a total accident when created(If ever actually created). 但是,我注意到结果包含一个过程,该过程在创建时似乎完全是偶然的(如果曾经创建过)。 In the database I have a procedure named ChatObject_Remove , this appeared in my query because I was looking for anything referencing the term %Remove% . 在数据库中,我有一个名为ChatObject_Remove的过程,该过程出现在我的查询中,因为我正在寻找任何引用术语%Remove% But I also see a ghost procedure called zzChatObject_Remove 但我也看到了一个名为zzChatObject_Remove幻影过程

In SSMS when I expand the database's Programmability -> Stored Procedures I see ChatObject_Remove , but not zzChatObject_Remove . 在SSMS中,当我扩展数据库的Programmability -> Stored Procedures ,看到的是ChatObject_Remove ,但没有看到的zzChatObject_Remove

I have tried refreshing this group and the ghost still does not appear. 我尝试刷新此组,但仍然没有出现该幻影。

I tried to use the statement 我尝试使用该语句

drop procedure [dbo].[zzChatObject_Remove]

which returned an error saying it either didn't exist or I didn't have permission. 它返回一个错误,指出它要么不存在,要么我没有权限。

I tried to create a procedure called zzChatObject_Remove and it allowed me to do it (but now I had 2 objects in sql_modules with a definition for create procedure zzChatObject_Remove ... ). 我尝试创建一个名为zzChatObject_Remove的过程,它允许我执行此操作(但现在sql_modules有2个对象, sql_modules带有create procedure zzChatObject_Remove ...的定义)。 I then deleted the new one which it allowed, and the ghost, as expected, is still in the modules table and I cannot touch it. 然后,我删除了它所允许的新文件,并且该鬼影仍在模块表中,正如我所料,我无法触摸它。

Has anyone seen this before? 谁看过这个吗? Where else could this be? 这还能在哪里呢? Could it do any harm? 会造成伤害吗? How can I get rid of this seemingly orphaned procedure in the sys.sql_modules table? 如何摆脱sys.sql_modules表中看似孤立的过程?

Thanks in advance for any input. 预先感谢您的任何投入。

Just my luck, seeing a ghost around Halloween time... 只是我的运气,在万圣节前夕看到一个幽灵...

Try this to see where it comes up: 试试看它出现在哪里:

exec sp_MSforeachdb '
    select ''?'' [db]
    , s.name [schema]
    , o.name [object]
    , o.type_desc 
    from [?].sys.objects o 
    inner join sys.schemas s 
        on s.schema_id = o.schema_id 
    where o.name = ''zzChatObject_Remove''
'

Or the following: 或以下内容:

select *
from sys.sql_modules sm
inner join sys.objects o 
    on o.object_id = sm.object_id
inner join sys.schemas s 
    on s.schema_id = o.schema_id 
where sm.description like '%zzChatObject_Remove%'

Also, to check, is this proc defined in sql_modules, or is it showing because it's referenced in the code of another procedure? 另外,要检查此过程是在sql_modules中定义的,还是因为在另一个过程的代码中引用了它而显示出来?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM