T-SQL: Getting all the tables having one column called XXX [duplicate]

This question already has an answer here:

I would like to have all the tables having one column called XXX

I’ve tried the following query but it’s not working.

SELECT object_id
FROM sys.columns 
WHERE name = 'XXX';

Comments 2

  • SELECT table_schema
         , table_name
         , column_name
    FROM   information_schema.columns
    WHERE  column_name LIKE '%test%'

    You’ve mentioned in your question comments that “it’s not working” =

    pressing F5 is aking me to create a report file

    In Management Studio you have a few options for what to do with your query results:

    enter image description here

    1. Results to Text CTRL + T
    2. Results to Grid (default) CTRL + D
    3. Results to File CTRL + SHIFT + F

    Sounds like you’ve hit the “Results to File” button (or key combination).

  • Here’s one that will grab both the column and the table it belongs to:

    SELECT DISTINCT so.name AS tablename, sc.name AS columnname 
    FROM syscolumns sc
    INNER JOIN sysobjects so
    ON so.id=sc.id
    WHERE sc.name LIKE '%XXX%'
    ORDER BY so.name, sc.name


电子邮件地址不会被公开。 必填项已用*标注