Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FIND DB TABLES/COLUMNS BY NAME - Use this script to find all columns, with a name that is similar to the search term
/******************************************
FIND DB TABLES/COLUMNS BY NAME
- Use this script to find all columns, with a name that is similar to
the search term
*******************************************/
/* Define column name to search for */
DECLARE @term varchar(20) = ''; -- e.g. 'user', 'gst', 'cpi'...etc
-- leave blank to return EVERY database table + column.
/* Find Tables & Columns */
SELECT t.name table_name, c.name column_name
FROM sys.columns c, sys.tables t
WHERE t.object_id = c.object_id
AND c.name LIKE '%' + @term + '%'
ORDER BY 1, 2 ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.