Database scan tool?

  • Does anyone have a script that would accept a column name and a value for that column as parameters and return all table names that have the column and the value? This would be a great help to me because I maintain a database with over 1,000 tables.

    "I hope you enjoy your retirement as much as I will."

    When the snows fall and the white winds blow,The lone wolf dies but the pack survives.

    Once you've accepted your flaws, no one can use them against you.

  • select * from sysobjects a, syscolumns b

    where a.id = b.id

    and b.name = 'YourColumnName'

    Darren


    Darren

  • Thanks Darren. That query will list all of the tables that contain the column. The final step is to query the listed tables and limit the result to those tables that contain the value I am looking for. Do you have a script that will do that?

    "I hope you enjoy your retirement as much as I will."

    When the snows fall and the white winds blow,The lone wolf dies but the pack survives.

    Once you've accepted your flaws, no one can use them against you.

  • Wrap the above query in a cursor, then for each table name from sysobjects you can dynamically build a select query then call EXECUTE passing in the sql statement with the appended table name and "where" clause.

    Darren


    Darren

Viewing 4 posts - 1 through 3 (of 3 total)

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