Search for table column

Looking for a field or piece of data, but you aren’t sure where it lives?

Try this handy query to search for it. I advice you save this somewhere so that you can use it often.

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 '% [SEARCH CRITERIA] %'
ORDER BY
	schema_name, 
	table_name;

Where SEARCH CRITERIA would be a keyword that you are looking for. E.g. employee or payment.

This script has helped me out countless times. Find the original post here.

Subscribe

0 comments