Saturday, August 3, 2013

Find Stored Procedures and Functions to Refer any Tables

Hi,
Just replace the "search" in the code with the name of the table/view/stored procedure/function etc that you want to search on


select        distinct
            ObjectType        = o.type_desc
        ,    ObjectName        = o.name
        ,    CodeSequence    = c_display.colid
        ,    Code            = c_display.[text]
from        sys.objects o
inner join    sys.syscomments c_search
            on c_search.id = o.[object_id]
inner join    sys.syscomments c_display
            on c_display.id = o.[object_id]
where        o.type_desc not in ('INTERNAL_TABLE','SERVICE_QUEUE','SYSTEM_TABLE')
and            c_search.[text] like '%search%'
order by    1, 2, 3

No comments:

Post a Comment