SELECT
co.Column_Name AS 'Name'
,co.Data_Type AS 'Type'
,ISNULL(co.Character_Maximum_Length, 0) AS 'Lenght'
,CASE WHEN co.Data_Type='Bit' AND NOT co.Column_Default IS NULL THEN
CASE WHEN REPLACE(REPLACE(REPLACE(ISNULL(co.Column_Default,''),'(',''),')',''),'''','') = 0 THEN 'False' ELSE 'True' END ELSE
CASE WHEN cu.Column_Name IS NULL THEN REPLACE(REPLACE(REPLACE(ISNULL(COLUMN_DEFAULT,''),'(',''),')',''),'''','') ELSE CASE WHEN tc.Constraint_Type = 'PRIMARY KEY' THEN '0' ELSE '' END END END AS 'DEFAULT'
,CASE WHEN tc.Constraint_Type = 'PRIMARY KEY' THEN cu.Column_Name ELSE NULL END AS 'PrimaryKey'
,CASE WHEN tc.Constraint_Type = 'UNIQUE' THEN cu.Column_Name ELSE NULL END AS 'Index'
FROM INFORMATION_SCHEMA.COLUMNS AS co
LEFT JOIN (INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS cu
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc ON cu.Constraint_Name = tc.Constraint_Name) ON co.Column_Name = cu.Column_Name AND cu.Table_Name = @TableName
WHERE co.Table_Name = @TableName
ORDER BY co.Ordinal_Position ASC