
正文
sqlserver获取表格列数,sql2008如何查看表的数量
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
SqlServer如何查询表的列数
select count(name) from syscolumns
where id=( select id from sysobjects where name='表名' and xtype='U')
说明:select id from sysobjects where name='表名' and xtype='U' 从sysobjects 里查询表类型为U(非系统)的表的id ,假设查到的是 1002 ;
select count(name) from syscolumns where id=1002 查的是系统列syscolumns 里表id是1002的列数。
你可以随便建个表,然后分步运行这两句看看
相关问答
Q1: 查询某个表中共有多少列 ? sql server!!
select name from syscolumns where id=object_id('tb_menu') --查询表名为tb_menu的所有列名
select count(name) from syscolumns where id=object_id('tb_menu') --查询表名为tb_menu的所有列名个数
Q2: 如何快速获得SQL Server 表行数
其实有两个办法可以快速的查询到SQL Server的表数据。1. sp_spaceused:其中有一列是rows,如果输入的表对象的话,那么就会获得这个表的行数,速度非常快。其中也有一个列为rowcnt,Counts the total number of inserted, deleted, or updated rows since the last time statistics were updated for the table 使用下面的语句:---replace the tablename when you use this script from sys.sysindexes where id =object_id('tablename') and indid in(0,1) 通过这个统计结果可能不是太准确,因为系统统计信息有个时间差
Q3: 如何在sqlserver中获取表的所有列信息
select * from sys.columns where object_id=object_id('table1')
使用上面语句就能查出来,其中name--该列的列名,column_id--该列在数据库中的ID,system_type_id--该列的类型的ID,和下面max_length,precision,scale三列一起可以来举个示例,max_length--该列的最大长度,precisionp--如果这列是数值列,那么这是该列的精度,否则就是0
,scale--如果这列是数值列,那么这就是列的小数位数,否则就是0
Q4: 求教sql server怎样求表1中的A列数据和B列数据
select sum(金额),count(1) as 总箱数 from 表A,表B where 表A.id=表B.id group by 表A.id
或者
select sum(金额),count(1) as 总箱数 from 表A left join 表B on 表A.id=表B.id group by 表A.id





