计算SQL Server中的列数 [英] Count number of columns in SQL Server
本文介绍了计算SQL Server中的列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以知道SQL中的列数,例如count()...?
Is there a way to know the number of columns in SQL, something like count()...?
推荐答案
一种方法
select count(*) from sys.columns
另一个
select count(*) from information_schema.columns
最下面的没有系统表
按表格
select count(*),table_name from information_schema.COLUMNS
GROUP BY table_name
仅表
select count(*),c.table_name
from information_schema.COLUMNS c
JOIN information_schema.tables t ON c.TABLE_NAME = t.TABLE_NAME
AND c.TABLE_Schema = t.TABLE_Schema
WHERE TABLE_TYPE = 'base table'
GROUP BY c.table_name
仅观看次数
select count(*),c.table_name
from information_schema.COLUMNS c
JOIN information_schema.tables t ON c.TABLE_NAME = t.TABLE_NAME
AND c.TABLE_Schema = t.TABLE_Schema
WHERE TABLE_TYPE = 'view'
GROUP BY c.table_name
这篇关于计算SQL Server中的列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文