Skip to content

Instantly share code, notes, and snippets.

@jibbius
Created April 24, 2013 07:50
Show Gist options
  • Save jibbius/5450395 to your computer and use it in GitHub Desktop.
Save jibbius/5450395 to your computer and use it in GitHub Desktop.
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