Microsoft SQL Server provides two methods for obtaining meta data: system stored procedures or information schema views.
Here are the SQL snippets for getting meta information about a database table in SQL Server. These queries could provide answer to the following requests:
- How to get the name of all columns of a table in SQL Server
- How to get colum and field type in SQL Server
- How to get meta data about SQL Server table
SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH
WHERE TABLE_NAME = [table_name]
ORDER BY COLUMN_NAME
SELECT * FROM sys.columns
WHERE object_id = OBJECT_ID('dbo.[table_name]')
We prefer the first solution over the second one (that gets information from "sys.columns") because in the frist case the query shows DATA_TYPE directly.