The following query can be run (substitute the ‘TableName’ in the query with the table name you want column information on) to get the column names for any table in T-SQL.
1 2 3 |
select column_name from information_schema.columns where table_name = 'TableName' order by ordinal_position |
1 |
To get information on all the columns for all tables in a database use the following query:
1 2 |
SELECT Table_Schema, Table_Name, Column_Name, Data_Type FROM information_schema.columns |
SQL Server also provides a stored procedure (‘sp_help’) which is able to display information on any object listed in sysobjects. To use this to get information on a table execute the following:
1 |
EXEC sp_help 'tablename' |