Thursday, April 11, 2019

Find all tables containing column with specified name - MS SQL Server

Search Tables:
SELECT      c.name  AS 'ColumnName'
            ,t.name AS 'TableName'
FROM        sys.columns c
JOIN        sys.tables  t   ON c.object_id = t.object_id
WHERE       c.name LIKE '%MyName%'
ORDER BY    TableName
            ,ColumnName;
Search Tables & Views:
SELECT      COLUMN_NAME AS 'ColumnName'
            ,TABLE_NAME AS  'TableName'
FROM        INFORMATION_SCHEMA.COLUMNS
WHERE       COLUMN_NAME LIKE '%MyName%'
ORDER BY    TableName
            ,ColumnName;

source: https://stackoverflow.com/questions/4849652/find-all-tables-containing-column-with-specified-name-ms-sql-server

No comments:

Post a Comment