I have a Microsoft SQL database and I want to know what columns and types it has. I'd prefer to do this through a query rather than using a GUI like Enterprise Manager. Is there a way to do this?
+7
A:
There are a few methods to get metadata about a table:
sp_help @tablename
Will return several result sets, describing the table, it's columns and constraints.
The INFORMATION_SCHEMA
views will give you the information you want, though unfortunately you have to query the views and join them manually.
Brannon
2008-11-26 00:28:06
+5
A:
You can use the sp_columns stored procedure:
exec sp_columns MyTable
Vincent Ramdhanie
2008-11-26 00:30:37
Thanks - I was about to post the same question with T-SQL instead of MSSQL.
Jedidja
2009-10-12 14:55:59
+4
A:
Just in case you don't want to use stored proc, here's a simple query version
select *
from information_schema.columns
where table_name = 'aspnet_Membership'
order by ordinal_position
Salamander2007
2008-11-26 01:05:32