Sunday, 22 April 2012

Get column names and datatypes in particular table using SQL Server


SELECT column_name as ColumnName,
data_type as DataType,
character_maximum_length as MaximumLength
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'Employee_Details'

Result:

ColumnName  DataType    MaximumLength
id          bigint      NULL
username    varchar     50
firstname   varchar     50
lastname    varchar     50
city        varchar     50
designation varchar     50
Salary      decimal     NULL

No comments:

Post a Comment