sql - List all columns referenced in all procedures of all databases -


is there way can columns , tables referenced in stored procedures in databases in instance? output should be:

database   procedure   table   column  --------   ---------   -----   ------ 

this list you're after, won't if have such column references embedded in dynamic sql (and may not find references rely on deferred name resolution). sql server doesn't parse text of stored procedure come dmv output.

try collate clauses deal cases have databases on same server different collations.

declare @sql nvarchar(max) = n'';  select @sql += n'union select    [database]  = ''' + replace(name, '''', '''''') + ''',   [procedure] = quotename(s.name) + ''.'' + quotename(p.name)                 collate latin1_general_ci_ai,    [table]     = quotename(referenced_schema_name) + ''.''                + quotename(referenced_entity_name)                 collate latin1_general_ci_ai,   [column]    = quotename(referenced_minor_name)                 collate latin1_general_ci_ai ' + quotename(name) + '.sys.schemas s inner join ' + quotename(name) + '.sys.procedures p on s.[schema_id] = p.[schema_id] cross apply ' + quotename(name)  + '.sys.dm_sql_referenced_entities' + '(quotename(s.name) + ''.'' + quotename(p.name), n''object'') d d.referenced_minor_id > 0' sys.databases    database_id > 4    , [state] = 0;  set @sql = stuff(@sql,1,11,'');  exec sp_executesql @sql; 

also cross apply syntax won't work if have databases in 80 compatibility mode. make sure don't execute code in such database , should work fine (even if of target databases in 80).


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -