Find all stored procedures that reference a specific column in some table

前端 未结 9 1858
广开言路
广开言路 2021-01-30 16:01

I have a value in a table that was changed unexpectedly. The column in question is CreatedDate: this is set when my item is created, but it\'s being changed by a st

相关标签:
9条回答
  • 2021-01-30 16:58

    You can use ApexSQL Search, it's a free SSMS and Visual Studio add-in and it can list all objects that reference a specific table column. It can also find data stored in tables and views. You can easily filter the results to show a specific database object type that references the column

    enter image description here

    Disclaimer: I work for ApexSQL as a Support Engineer

    0 讨论(0)
  • 2021-01-30 16:59

    i had the same problem and i found that Microsoft has a systable that shows dependencies.

    SELECT 
        referenced_id
        , referenced_entity_name AS table_name
        , referenced_minor_name as column_name
        , is_all_columns_found
    FROM sys.dm_sql_referenced_entities ('dbo.Proc1', 'OBJECT'); 
    

    And this works with both Views and Triggers.

    0 讨论(0)
  • 2021-01-30 17:01

    One option is to create a script file.

    Right click on the database -> Tasks -> Generate Scripts

    Then you can select all the stored procedures and generate the script with all the sps. So you can find the reference from there.

    Or

    -- Search in All Objects
    SELECT OBJECT_NAME(OBJECT_ID),
    definition
    FROM sys.sql_modules
    WHERE definition LIKE '%' + 'CreatedDate' + '%'
    GO
    
    -- Search in Stored Procedure Only
    SELECT DISTINCT OBJECT_NAME(OBJECT_ID),
    object_definition(OBJECT_ID)
    FROM sys.Procedures
    WHERE object_definition(OBJECT_ID) LIKE '%' + 'CreatedDate' + '%'
    GO
    

    Source SQL SERVER – Find Column Used in Stored Procedure – Search Stored Procedure for Column Name

    0 讨论(0)
提交回复
热议问题