July 4, 2012

SQL SERVER – Query to Search Columns From a Database

Find Columns Inside a DataBase

The following query is used to find columns from all the tables of a database.
 -- ======================
 -- SEARCH TABLE COLUMNS
 -- ======================
 SELECT 
    TABLE_CATALOG,
    TABLE_NAME,
    COLUMN_NAME,
    ORDINAL_POSITION,
    IS_NULLABLE,
    DATA_TYPE,
    CHARACTER_MAXIMUM_LENGTH,
    NUMERIC_PRECISION,
    NUMERIC_SCALE
 FROM INFORMATION_SCHEMA.COLUMNS
 WHERE COLUMN_NAME LIKE '%ColumnName%'
 ORDER BY TABLE_NAME

No comments:

Post a Comment