(MSSQL)尋找含有特定欄位名稱的Tables/Views

搜尋含有特定欄位名稱的Tables

1
2
3
4
5
6
7
-- Search tables with specified column name
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;

搜尋含有特定欄位名稱的Tables & Views

1
2
3
4
5
6
-- Search tables & views with specified column name
SELECT COLUMN_NAME AS 'ColumnName',
TABLE_NAME AS 'TableName'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%MyName%'
ORDER BY TableName, ColumnName;