Find all references to an object in an SQL Server database

后端 未结 10 1707
深忆病人
深忆病人 2020-12-13 10:02

I\'m trying to find all references to an object in an SQL Server database.

How can I quickly search? SQL Server Management Studio does not seem to do it. I use http:

10条回答
  •  北海茫月
    2020-12-13 10:29

    Use:

    select object_name(m.object_id), m.*
      from sys.sql_modules m
     where m.definition like N'%name_of_object%'
    

    ...because SYSCOMMENTS and INFORMATION_SCHEMA.routines have nvarchar(4000) columns. So if "name_of_object" is used at position 3998, it won't be found. SYSCOMMENTS does have multiple lines, but INFORMATION_SCHEMA.routines truncates.

提交回复
热议问题