获取表格结构的一些简要信息,可以生成自己需要的字典,简单又实用!

以数据表MF_MO为例:

sql查询字段类型长度(sql获取表结构信息)(1)

--更新于2020-04-24 SELECT OBJECT_NAME(B.ID) 表名,B.COLORDER 序号,B.NAME 字段名称,C.NAME 字段类型,B.PREC 精度级别,B.SCALE 小数位数, CASE WHEN NOT F.ID IS NULL THEN 'TRUE' ELSE '' END 是否主键, CASE WHEN COLUMNPROPERTY(B.ID,B.NAME,'ISIDENTITY') = 1 THEN 'TRUE' ELSE '' END AS 是否自动增长, CONVERT(VARCHAR(1000),ISNULL(G.VALUE,'')) 字段说明 FROM SYSOBJECTS A INNER JOIN SYSCOLUMNS B ON A.ID=B.ID INNER JOIN SYSTYPES C ON B.XTYPE=C.XUSERTYPE LEFT JOIN SYSOBJECTS D ON B.ID=D.PARENT_OBJ AND D.XTYPE='PK' LEFT JOIN SYSINDEXES E ON B.ID=E.ID AND D.NAME=E.NAME LEFT JOIN SYSINDEXKEYS F ON B.ID=F.ID AND B.COLID=F.COLID AND E.INDID=F.INDID LEFT JOIN SYS.EXTENDED_PROPERTIES G ON B.ID=G.MAJOR_ID AND B.COLID=G.MINOR_ID WHERE A.XTYPE='U' AND OBJECT_NAME(B.ID)='MF_MO'

sql查询字段类型长度(sql获取表结构信息)(2)

执行结果如下:

sql查询字段类型长度(sql获取表结构信息)(3)

,