Tuesday, October 20, 2015

MS SQL Server - Select Columns Names with System Type for User Table

declare @tableName varchar(max)
set @tableName = 'Products'

select so.name as TableName, sc.name as ColumnName, st.name as SystemType
from sys.columns sc
inner join sys.objects so on (sc.object_id = so.object_id)
inner join sys.types st on (sc.system_type_id = st.system_type_id)
where
    (so.type_desc = 'USER_TABLE')
    and
    (so.name = @tableName)