如何获取一个表的,字段,类型,长度,是否主键,是否为空,注释 等信息

[复制链接]
查看11 | 回复1 | 2007-10-20 08:38:44 | 显示全部楼层 |阅读模式
//可以获取表名称
select name from sysobjects where type='U'
//可以获取列的相关信息
select * from syscolumns where id=object_id('CODEFIELD')
问题是, syscolumns 里面大部分的字段我都不知道干什么的能给个解释吗?
例如type=38 39 。。。对应的都是什么类型。
回复

使用道具 举报

千问 | 2007-10-20 08:38:44 | 显示全部楼层
select object_name(c.id) objname, c.colid colid, c.name colname, (case (c.status & 12 when 0 then t2.name else 'identity' end) coltype,

c.length collen, (case (c.status &when 0 then 'not null' else 'null' end) allownull
from syscolumns c, systypes t1, systypes t2
where c.id = object_id('CODEFIELD')

and c.usertype = t1.usertype and t1.type = t2.type

and t2.usertype = (select min(m.usertype) from dbo.systypes m where t2.type = m.type)
order by 1, 2
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行