-
Notifications
You must be signed in to change notification settings - Fork 0
/
dependencies.sql
34 lines (28 loc) · 1.06 KB
/
dependencies.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
USE [AdventureWorks2012]
GO
--dependencies by text
select s.name +'.' + o.name, o.type_desc, m.definition, LEN(m.definition)
from sys.sql_modules m
inner join sys.objects o on m.object_id = o.object_id
inner join sys.schemas s on s.schema_id = o.schema_id
where definition like '%JobCode%'
order by o.name
--dependencies by dependency
select
ReferencingObjectName = rs.name + '.' + ro.name
, ReferencingObjectType = ro.type_desc
, ReferencedObjectName = s.name + '.' + o.name
, ReferencedObjectType = o.type_desc
from sys.sql_expression_dependencies d
inner join sys.objects o on d.referenced_id = o.object_id or d.referenced_minor_id = o.object_id
inner join sys.schemas s on o.schema_id = s.schema_id
inner join sys.objects ro on d.referencing_id = ro.object_id
inner join sys.schemas rs on ro.schema_id = rs.schema_id
where
-- ro.is_ms_shipped = 0
--and o.is_ms_shipped = 0
--and op.type_desc = 'SQL_STORED_PROCEDURE'
--and s.name = 'Loading'
o.name like '%JobCode%'
group by rs.name , ro.name, s.name , o.name , ro.type_desc, o.type_desc
order by ro.name, o.name