Created
April 24, 2013 07:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************** | |
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