Scott
Scott

Reputation: 13931

SQL query to find all tables in a database that have a column with a specific name

What query can I run on a database that will tell me which tables in that database have a column named "RCPTNMBR"?

Upvotes: 7

Views: 13256

Answers (2)

Ken Downs
Ken Downs

Reputation: 4827

Most databases support this:

SELECT 
    table_name 
FROM 
    information_schema.columns 
WHERE
    column_name = 'x'

Upvotes: 15

bobs
bobs

Reputation: 22194

Give this a try

SELECT t.name as TableName, c.name as ColumnName
FROM sys.tables t
JOIN sys.columns c ON t.object_id = c.object_id
WHERE c.name = 'RCPTNMBR'

Upvotes: 1

Related Questions