sql server查询表中各列名称、表中列数
1、查询表名为test的所有列名:
select name from syscolumns where id=object_id('test')
2、查询表名为test的所有列名个数
select count(name) from syscolumns where id=object_id('test')
或者
select count(syscolumns.name)
from syscolumns ,sysobjects
where syscolumns.id=sysobjects.id and sysobjects.name = 'test'
3、针对dy_news数据库中的表info,有如下查询:
例子:
select name,length,(case type
when 56 then 'a'
when 39 then 'b'
when 35 then 'c'
else cast(type as varchar(10))
end),status,collation from syscolumns where id=object_id('info')
注意,这里cast函数的用法,用于数字类型到字符串类型的转换。
例子:
select name from sysobjects
where name='info'
select id from syscolumns where id=object_id('info')