How to find all column dependencies including triggers?

  • Hi,

    There was a situation when a column was removed from a table via some external web application, and after that a bunch of "invalid column name" sql errors generated in app's log.

    The reason was that due to apparently app's bug, it did not update table's trigger that was still using the deleted column name in its code... What would be a best way to see ALL column dependencies?

    Thanks!

  • Search for the column name in syscomments

  • arnipetursson (3/7/2013)


    Search for the column name in syscomments

    syscomments is there for backward compatibility only.

    Use sys.sql_modules in SQL 2005 and newer. The definition column contains the T-SQL code for the module.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • syscomments is there for backward compatibility only.

    Use sys.sql_modules in SQL 2005 and newer. The definition column contains the T-SQL code for the module.

    here is the code to find the dependencies..

    select OBJECT_NAME(object_id) from sys.sql_modules where definition like '%column_name%'

    ~ demonfox
    ___________________________________________________________________
    Wondering what I would do next , when I am done with this one :ermm:

  • This is exactly it,

    Thanks so much guys

  • Bear in mind that it's not infallible. If I use select * from mytable inside my procedure you won't find the column you're looking for. You might want to check any procedures that contain the tablename which contains your column as well.

  • from my snippets on finding dependencies for a specific column name;

    SELECT

    depz.referenced_schema_name,

    depz.referenced_entity_name,

    objz.type_desc,

    colz.name AS ColumnName

    FROM sys.sql_expression_dependencies depz

    INNER JOIN sys.objects objz ON depz.referenced_id=objz.object_id

    LEFT OUTER JOIN sys.columns colz ON objz.object_id = colz.object_id

    AND colz.column_id = referencing_minor_id

    --WHERE referencing_id = OBJECT_ID(N'MyTable');

    WHERE colz.name = 'EmployeeNumber'

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • The last one I could not get working for some reason, but i'll take another look

    Thanks again

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply