(CASE WHEN a.ifnullable = 1 THEN 0 ELSE 1 END) AS is_required,
(CASE WHEN (
SELECT COUNT(*) FROM sysobjects
WHERE (name IN (
SELECT name FROM sysindexes
WHERE (id = a.id)
AND (indid IN (
SELECT indid FROM sysindexkeys
WHERE (id = a.id)
AND (colid IN (SELECT colid FROM syscolumns WHERE (id = a.id) AND (name = a.name)))
))))
AND (xtype = 'PK')
) > 0 THEN 1
ELSE 0 END) AS is_pk,
a.colorder AS sort,
ifnull(g.[value], ' ') AS column_comment,
(CASE WHEN COLUMNPROPERTY(a.id, a.name, 'IsIdentity') = 1 THEN 1 ELSE 0 END) AS is_increment,
b.name AS column_type
FROM syscolumns as a
LEFT JOIN systypes b ON a.xtype = b.xusertype
INNER JOIN sysobjects d ON a.id = d.id AND d.xtype = 'U' AND d.name <![CDATA[<>]]> 'dtproperties'
LEFT JOIN syscomments e ON a.cdefault = e.id
LEFT JOIN sys.extended_properties g ON a.id = g.major_id AND a.colid = g.minor_id
LEFT JOIN sys.extended_properties f ON d.id = f.class AND f.minor_id = 0
LEFT JOIN sys.objects h ON a.id = h.object_id
LEFT JOIN sys.schemas i ON h.schema_id = i.schema_id
WHERE d.name = #{tableName}
ORDER BY a.colorder
select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else '0' end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})