How to Find the list of Stored Procedures which affect a particular column?

后端 未结 5 995
心在旅途
心在旅途 2021-01-12 05:48

Im working on this large DB which has a lot of the business knowledge embedded in the SPs[I know!] and there is a lot of chaining between the SPs. i.e one stored proc callin

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-12 06:14

    From system view sys.sql_dependencies you can get dependencies at column level.

    DECLARE @Schema SYSNAME
    DECLARE @Table SYSNAME
    DECLARE @Column SYSNAME
    
    SET @Schema = 'dbo'
    SET @Table = 'TableName'
    SET @Column = 'ColumnName'
    
    SELECT o.name
    FROM sys.sql_dependencies AS d
      INNER JOIN sys.all_objects AS o ON o.object_id = d.object_id
      INNER JOIN sys.all_objects AS ro ON ro.object_id = d.referenced_major_id
      INNER JOIN sys.all_columns AS c ON c.object_id = ro.object_id AND c.column_id = d.referenced_minor_id
    WHERE (SCHEMA_NAME(ro.schema_id)=@Schema) 
      and o.type_desc = 'SQL_STORED_PROCEDURE'
      and ro.name = @Table
      and c.name = @Column
    GROUP BY o.name
    

提交回复
热议问题