• 全部
  • 基础类
  • 应用实例
  • 新技术前沿

有什么方法可以读取某个表中字段的名称、数据类型和描述

xiyahui 2003-05-20 10:04:47
我用的SQLSERVER2000,因为原来起的字段名是英文,现在要加上中文的说明,所以只能加到字段的描述里,用于一些用用文显示的地方。所以现在要读出字段的描述值。
感谢leimin给出下面的代码,可以得到student表的字段名称,数据类型和描述,还有其它什么方法可以读出这些信息吗?
SELECT
COLUMN_NAME,
ORDINAL_POSITION,
DATA_TYPE,
name AS PROPERTY_NAME,
value AS PROPERTY_VALUE
FROM INFORMATION_SCHEMA.COLUMNS AS C
Left JOIN ::fn_listextendedproperty (NULL, 'user', 'dbo', 'table', 'student',
'column', default) AS E
ON C.COLUMN_NAME = E.objname
WHERE TABLE_NAME = 'student'
...全文
10 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
erigido 2003-05-21
学习
回复
firetoucher 2003-05-21
sp_help table_name
回复
pengdali 2003-05-20
光要描述值

SELECT * FROM ::fn_listextendedproperty (NULL, 'user', 'dbo', 'table', 'testtable',
'column', default)
回复
pengdali 2003-05-20
select rtrim(b.name) as colname
,case when h.id is not null then 'PK' else '' end as primarykey
,type_name(b.xusertype) + case when b.colstat & 1 = 1 then '[ID(' + convert(varchar,ident_seed(a.name)) + ',' + convert(varchar,ident_incr(a.name)) + ')]' else '' end as type
,b.length
,case b.isnullable when 0 then 'N' else 'Y' end as [isnull]
,isnull(e.text,'') as [default]
,isnull(c.value,'') as descript
from sysobjects a,syscolumns b
left outer join sysproperties c on b.id = c.id and b.colid = c.smallid
left outer join syscomments e on b.cdefault = e.id
left outer join (select g.id,g.colid from sysindexes f,sysindexkeys g where f.id = g.id and f.indid = g.indid and f.indid > 0 and f.indid < 255 and (f.status & 2048)<>0) h on b.id = h.id and b.colid = h.colid
where a.id = b.id
and a.id = object_id('titles') --tablename改成你要导出的表的名称
order by b.colid
回复
pengdali 2003-05-20
SELECT
COLUMN_NAME,
ORDINAL_POSITION,
DATA_TYPE,
name AS PROPERTY_NAME,
value AS PROPERTY_VALUE
FROM INFORMATION_SCHEMA.COLUMNS AS C
Left JOIN ::fn_listextendedproperty (NULL, 'user', 'dbo', 'table', '你的表名',
'column', default) AS E
ON C.COLUMN_NAME = E.objname
WHERE TABLE_NAME = '你的表名'
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2003-05-20 10:04
社区公告
暂无公告