把以下的脚本放在查询分析器中,就可以看到执行结果了
select a.name 表名,
case when d.keyno is null then
null else
d.keyno end 主外键顺序,
b.name 字段名,
c.name 字段类型,
case when b.name in (N'nchar', N'nvarchar') then
b.length/2 else
b.length end 数据长度,
case when c.name in (N'decimal',N'numeric') then
ColumnProperty(object_id(a.name), b.name, N'Precision') else
NULL end 精度,
case when c.name in (N'decimal',N'numeric') then
ColumnProperty(object_id(a.name), b.name, N'Scale') else
NULL end 小数位,
ColumnProperty(object_id(a.name), b.name, N'IsIdentity') 标识,
case when (ColumnProperty(object_id(a.name), b.name, N'IsIdentity') <> 0) then
CONVERT(nvarchar(40), ident_seed(a.name)) else
null end 标识种子,
case when (ColumnProperty(object_id(a.name), b.name, N'IsIdentity') <> 0) then
CONVERT(nvarchar(40), ident_incr(a.name)) else
null end 标识自增量,
b.isnullable [允许空],
f.text 默认值
from dbo.sysobjects a
left join dbo.syscolumns b on a.id=b.id
left join dbo.systypes c on b.xtype=c.xtype
left join dbo.sysindexkeys d on a.id=d.id and b.colid=d.colid and d.indid=2
left join dbo.syscomments f on b.cdefault=f.id
where a.xtype='U'
order by a.name,b.colid