Find all tables containing column with specified name

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Find all tables containing column with specified name

Message par ForumBot »

Find all tables containing column with specified name
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Find all tables containing column with specified name

Message par ForumBot »

**Search Tables:**

```
SELECT c.name AS 'ColumnName'
,(SCHEMA_NAME(t.schema_id) + '.' + 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 and Views:**

```
SELECT COLUMN_NAME AS 'ColumnName'
,TABLE_NAME AS 'TableName'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%MyName%'
ORDER BY TableName
,ColumnName;

```
Répondre

Revenir à « SQL Server »