MSSQL server 如何查询一个表所有的列


功能说明:
1、通过本文,我们可以快速获取一个表的所有列
2、可以检测一个表中是否包含某一列

常用语句如下:
1 检测一个表所有列

select a.name as [表名], b.name as [列名]
from sysobjects a
left join syscolumns b on a.id = b.id and a.xtype = ‘U’
where a.name =’表名’

2 检测包含某一列的所有表
select a.name as [表名], b.name as [列名]
from sysobjects a
left join syscolumns b on a.id = b.id and a.xtype = ‘U’
where b.name =’列名’

3 检测一个表是否包含 特定列

select a.name as [表名], b.name as [列名]
from sysobjects a
left join syscolumns b on a.id = b.id and a.xtype = ‘U’
where
a.name =’表名’
and
b.name =’待检测列名’