gpt4 book ai didi

sql-server-2008 - 计算 SQL Server 中的列数

转载 作者:行者123 更新时间:2023-12-01 06:55:21 25 4
gpt4 key购买 nike

有没有办法知道 SQL 中的列数,比如 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-2008 - 计算 SQL Server 中的列数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5902764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com