取MS SQL 2005的数据库结构
select
表名 = case when A.colorder = 1 then D.name else ' ' end,
表说明 = case when A.colorder = 1 then ISNULL(F.VALUE, ' ') else ' ' end,
字段序号 = A.COLORDER,
字段名 = A.name,
标识 = case when columnproperty(A.ID,A.name, 'isidentity') = 1 then '√' else '' end,
主键 = case when exists(
select 1 from SYSOBJECTS
where XTYPE = 'PK ' and PARENT_OBJ=A.ID
and name IN (
select name from SYSINDEXES
where INDID IN (
select INDID from SYSINDEXKEYS
where ID = A.ID and COLID = A.COLID
)
)
) then '√ ' else ' ' end,
类型 = B.name,
字段大小 = A.LENGTH,
小数位数 = ISNULL(columnproperty(A.ID,A.name, 'SCALE '),0),
允许空 = case when A.ISNULLABLE=1 then '√ 'else ' ' end,
预设值 = ISNULL(E.TEXT, ' '),
字段说明 = ISNULL(G.[VALUE], ' ')
from SYSCOLUMNS A
left join SYSTYPES B on A.XUSERTYPE = B.XUSERTYPE
inner join SYSOBJECTS D on A.ID = D.ID and D.XTYPE = 'U ' and D.name <> '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.major_id and F.minor_id = 0