1 SELECT a.Table_schema as 架构 ,a.Table_name as 表名 ,b.COLUMN_NAME as 栏位名称,b.DATA_TYPE as 数据类型,isnull(b.CHARACTER_MAXIMUM_LENGTH,'') as 长度
2 ,COLUMNPROPERTY(OBJECT_ID(a.Table_name), b.COLUMN_NAME, 'IsIdentity') as 标识列,
3 (
4 select count(1) from syscolumns
5 join sysindexkeys on syscolumns.id=sysindexkeys.id and syscolumns.colid=sysindexkeys.colid
6 join sysindexes on syscolumns.id=sysindexes.id and sysindexkeys.indid=sysindexes.indid
7 join sysobjects on sysindexes.name=sysobjects.name and sysobjects.xtype='PK'
8 WHERE syscolumns.name=b.COLUMN_NAME AND syscolumns.id=object_id(a.Table_name )
9 ) as 主键
10 ,isnull(b.COLUMN_DEFAULT,'') as 预设值
11 ,b.IS_NULLABLE as 是否允许空值
12 ,( SELECT value
13 FROM fn_listextendedproperty (NULL, 'schema', a.Table_schema, 'table', a.TABLE_NAME, 'column', default)
14 WHERE name='MS_Description' and objtype='COLUMN'and objname Collate Chinese_Taiwan_Stroke_CI_AS = b.COLUMN_NAME
15 ) as 栏位备注
16 FROM INFORMATION_SCHEMA.TABLES a
17 LEFT JOIN INFORMATION_SCHEMA.COLUMNS b
18 ON a.TABLE_NAME = b.TABLE_NAME
19 ORDER BY a.TABLE_NAME, b.ORDINAL_POSITION
20
21 GO