Monday, May 24, 2021

Retrieve all Table detail from Known Column in SQL Server

This query will return all COLUMNS and their associated TABLES for a given column name.

It is designed to show you what are the tables (unknown) contain a specified column (known)

SQL Code:

USE AdventureWorks2017
GO

SELECT
c.name AS ColName,
t.name AS TableName
FROM
sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE
c.name LIKE 'Departmentid' --provide known column name here

Output:


Related Article:


No comments:

Post a Comment