1 SELECT 表名 = CASE WHEN a.colorder = 1 THEN d.name 2 ELSE '' 3 END , 4 表说明 = CASE WHEN a.colorder = 1 THEN ISNULL(f.value, '') 5 ELSE '' 6 END , 7 字段序号 = a.colorder , 8 字段名 = a.name , 9 标识 = CASE WHEN COLUMNPROPERTY(a.id, a.name, 'IsIdentity') = 1 THEN '√'10 ELSE ''11 END ,12 主键 = CASE WHEN EXISTS ( SELECT 113 FROM sysobjects14 WHERE xtype = 'PK'15 AND name IN (16 SELECT name17 FROM sysindexes18 WHERE indid IN (19 SELECT indid20 FROM sysindexkeys21 WHERE id = a.id22 AND colid = a.colid ) ) )23 THEN '√'24 ELSE ''25 END ,26 类型 = b.name ,27 占用字节数 = a.length ,28 长度 = COLUMNPROPERTY(a.id, a.name, 'PRECISION') ,29 小数位数 = ISNULL(COLUMNPROPERTY(a.id, a.name, 'Scale'), 0) ,30 允许空 = CASE WHEN a.isnullable = 1 THEN '√'31 ELSE ''32 END ,33 默认值 = ISNULL(e.text, '') ,34 字段说明 = ISNULL(g.[value], '')35 FROM syscolumns a36 LEFT JOIN systypes b ON a.xtype = b.xusertype37 INNER JOIN sysobjects d ON a.id = d.id38 AND d.xtype = 'U'39 AND d.name <> 'dtproperties'40 LEFT JOIN syscomments e ON a.cdefault = e.id41 LEFT JOIN sys.extended_properties g ON a.id = g.major_id42 AND a.colid = g.minor_id43 LEFT JOIN sys.extended_properties f ON d.id = f.major_id44 AND f.minor_id = 0 45 46 --where d.name='要查询的表' --如果只查询指定表,加上此条件 47 ORDER BY a.id ,48 a.colorder
结果: