问题描述
- MS SQL怎么根据表名查询表中的字段相关信息
-
MS SQL怎么根据表名查询表中的字段相关信息,包括字段的名称,类型,备注信息select syscolumns.name,systypes.name as type,(select isnull(value,'') from sys.extended_properties ex_p where ex_p.minor_id=0 and ex_p.major_id=sysobjects.id) as TableDemo ,ext.value as colName from syscolumns INNER JOIN sysobjects ON syscolumns.id = sysobjects.id INNER JOIN systypes ON syscolumns.xtype = systypes.xtype INNER join sys.extended_properties as ext on ext.major_id=sysobjects.id and ext.minor_id=syscolumns.colorder WHERE (sysobjects.name = 'tf_site') AND (systypes.name<>'sysname')
为什么上面这个代码读取不出来呢?
请大神帮助下,要字段有备注或没有备注时都能查询出来,谢谢!
解决方案
select syscolumns.name,
systypes.name as type,
(select isnull(value, '')
from sys.extended_properties ex_p
where ex_p.minor_id = 0
and ex_p.major_id = sysobjects.id) as TableDemo,
ext.value as colName
from syscolumns
INNER JOIN sysobjects /* 内连接*/
ON syscolumns.id = sysobjects.id
INNER JOIN systypes
ON syscolumns.xtype = systypes.xtype
INNER join sys.extended_properties as ext /* 内连接*/
on ext.major_id = sysobjects.id
and ext.minor_id = syscolumns.colorder
WHERE (sysobjects.name = 'tf_site')
AND (systypes.name <> 'sysname')
时间: 2024-12-31 05:33:40