List Tables and Columns in a SQL Server Database
Some useful queries for table and column information in SQL Server
- This query lists the tables in a SQL Server database
select * from [databaseName].INFORMATION_SCHEMA.TABLE
- This query lists the table names and column names in a SQL Server database
select TABLE_NAME, COLUMN_NAMEfrom [databaseName].INFORMATION_SCHEMA.COLUMNSorder by TABLE_NAME, ORDINAL_POSITION
- This query lists the column names in a table
select COLUMN_NAMEfrom [databaeseName].INFORMATION_SCHEMA.COLUMNSwhere TABLE_NAME = N'tableName'
Hope it helps!
Originally published at http://www.weboideas.com on June 27, 2014.