Share This!

Monday, August 3, 2015

Select a List of Column Names in SQL Server

This gives a list of all the tables and columns in the tables in your database.  The TABLES table was included to exclude views.
Select
    COLUMNS.TABLE_SCHEMA, 
    COLUMNS.TABLE_NAME,
    COLUMNS.COLUMN_NAME
from INFORMATION_SCHEMA.COLUMNS
inner join
    INFORMATION_SCHEMA.TABLES
    on Tables.TABLE_CATALOG = Columns.TABLE_CATALOG
        and Tables.TABLE_SCHEMA = Columns.TABLE_SCHEMA
        and Tables.TABLE_NAME = COLUMNS.TABLE_NAME
        and Tables.TABLE_TYPE = 'BASE TABLE'
 


...

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

No comments:

Post a Comment

Contact Us

Name

Email *

Message *