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')

为什么上面这个代码读取不出来呢?

请大神帮助下,要字段有备注或没有备注时都能查询出来,谢谢!

1个回答

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')

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐