Find a value anywhere in a database

前端 未结 18 884
小蘑菇
小蘑菇 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:01

    Suppose if you want to get all the table with name a column name contain logintime in the database MyDatabase below is the code sample

        use MyDatabase
    
        SELECT t.name AS table_name,
        SCHEMA_NAME(schema_id) AS schema_name,
        c.name AS column_name
        FROM sys.tables AS t
        INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
        WHERE c.name LIKE '%logintime%'
        ORDER BY schema_name, table_name;
    

提交回复
热议问题