SQL statement to get column type
Is there a SQL statement that can return the type of a column in a table?
Using SQL Server:
SELECT DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'yourTableName' AND
COLUMN_NAME = 'yourColumnName'
The easiest way in TSQL is:
SELECT COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'yourTableName'
For SQL Server, this system stored procedure will return all table information, including column datatypes:
exec sp_help YOURTABLENAME
In TSQL/MSSQL it looks like:
SELECT t.name, c.name
FROM sys.tables t
JOIN sys.columns c ON t.object_id = c.object_id
JOIN sys.types y ON y.user_type_id = c.user_type_id
WHERE t.name = ''