Skip to content

Instantly share code, notes, and snippets.

@kdarty
Created December 31, 2015 14:25
Show Gist options
  • Save kdarty/15a806b55799280ff968 to your computer and use it in GitHub Desktop.
Save kdarty/15a806b55799280ff968 to your computer and use it in GitHub Desktop.
Ever need to find what Tables have reference to a certain Column? This SQL Script will query the System Tables to find all references to a given Column Name. A GUI like SSMS would be helpful but it is nice to have an easy script to produce such a report. Source: http://blog.sqlauthority.com/2008/08/06/sql-server-query-to-find-column-from-all-tab…
USE [DatabaseName]
GO
-- Searcj all Tables for a given Column Name
-- Refine WHERE Clause to suit your needs
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c
ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%ColumnName%'
ORDER BY schema_name,
table_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment