Home » List the data types of all columns of a Table

List the data types of all columns of a Table

When Developing a Package/TSQL, I find the below query really helpful in identifying List the data types of all columns of a Table


--Script 1 : Simple script to identify the data types of all the columns in specific database customizable for particular data type
--This script also usefull for checking data types of all columns of particular table using second where clause below
SELECT OBJECT_NAME(col.OBJECT_ID) TableName, col.name as "Column Name", t.name, *
FROM sys.columns AS col
JOIN sys.types AS t ON col.user_type_id=t.user_type_id
--to find a particular table's all columns use where clause below
--where OBJECT_NAME(col.OBJECT_ID) = 'Put table name here'
--you can use this where clause to check particular data types
--and t.name = 'int'
ORDER BY col.OBJECT_ID;
GO

Leave a Reply

Your email address will not be published. Required fields are marked *