首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

如何得出一个表中列的数量呢

2012-01-29 
怎么得出一个表中列的数量呢?如题。[解决办法]select count(1) from 表[解决办法]select count(*) as 字段

怎么得出一个表中列的数量呢?
如题。

[解决办法]
select count(1) from 表
[解决办法]
select count(*) as 字段数量 from syscolumns where id=object_id( '表名 ')
[解决办法]
select count(*) as 字段个数
from syscolumns
where id=object_id( '表名 ')
[解决办法]
select count(列名) as 别名 from 表名
[解决办法]

探讨
也对,可是,如果是想获得一个表有多少个字段怎么获得呢?

[解决办法]
select count(*) from syscolumns 
where id = object_id( '表名 ')
[解决办法]
select count(b.name) from sysobjects a,syscolumns b where a.id=b.id and a.name=tbname group by b.name
[解决办法]
SQL code
select count(*) as column_count from syscolumns where id=object_id('table_name')
[解决办法]
select count(*) as 字段数量 from syscolumns where id=object_id( '表名 ') 

[解决办法]
select count(*) as 字段个数 
from syscolumns 
where id=object_id( '表名')

热点排行