Find a value anywhere in a database

前端 未结 18 1157
小蘑菇
小蘑菇 2020-11-22 03:52

Given a #, how do I discover in what table and column it could be found within?

I don\'t care if it\'s fast, it just needs to work.

18条回答
  •  爱一瞬间的悲伤
    2020-11-22 04:23

    Thanks for the really useful script.

    You may need to add the following modification to the code if your tables have non-convertable fields:

    SET @ColumnName =
        (
            SELECT MIN(QUOTENAME(COLUMN_NAME))
            FROM    INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_SCHEMA    = PARSENAME(@TableName, 2)
                AND TABLE_NAME  = PARSENAME(@TableName, 1)
                AND DATA_TYPE NOT IN ('text', 'image', 'ntext')                 
                AND QUOTENAME(COLUMN_NAME) > @ColumnName
        )
    

    Chris

提交回复
热议问题