简体   繁体   English

数据库中所有表中的字段总数

[英]Total number of fields in all tables in database

I have a huge database with hundreds of tables and I want to find out the total fields (columns) defined in all of the tables. 我有一个包含数百个表的庞大数据库,我想找出所有表中定义的总字段(列)。

Is there a sql query that can give me that? 有没有可以给我的SQL查询? If not, what would be the best way? 如果没有,最好的方法是什么?

Is this what you want? 这是你想要的吗?

select count(*)
from information_schema.columns
where table_schema = 'your_schema'

You can run it like this to see if it is reasonable: 您可以像这样运行它以查看它是否合理:

select table_name, column_name
from information_schema.columns
where table_schema = 'your_schema'
order by 1, 2

试试这个(登录到当前架构时):

select count(*) from information_schema.columns where table_schema = DATABASE();

I am new in mysql but if table information_schema.columns is the table with table_name and column_name information then you can use following query 我在mysql中是新的,但如果表INFORMATION_SCHEMA.COLUMNS表名列名的信息,那么你可以使用下面的查询表

select table_name, count( distinct column_name ) column_number_used
from information_schema.columns 
where table_schema = 'your_schema' 
group by table_name

this should give all table names with respective column number used in that table.. 这应该为所有表名提供该表中使用的相应列号。

Below example may works and modify queries as per your requirement. 下面的示例可以根据您的要求工作和修改查询。

Use [Your_DB_Name]

/* Count Total Number Of Tables */
SELECT COUNT(*) AS 'Total Tables' FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'

/* Count Total Number Of Views */
SELECT COUNT(*)  AS 'Total Views'  FROM INFORMATION_SCHEMA.VIEWS

/* Count Total Number Of Stored Procedures */
SELECT COUNT(*)  AS 'Total SPs'  FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE'

/* Count Total Number Of UDF(User Defined Functions) */
SELECT COUNT(*)  AS 'Total Functions' FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'FUNCTION'

Example: 例:

在此输入图像描述

Try this: 试试这个:

SELECT COUNT(*) 
FROM INFORMATION_SCHEMA.COLUMNS

You can get the queries you need from this open source project called anywhereindb . 您可以从这个名为anywhereindb的开源项目中获取所需的查询。 The final result of this project goes further than you need, but you can look into the code and take out the part where it figures out all the parts of the tables. 这个项目的最终结果比你需要的更进一步,但是你可以查看代码并取出它找出表格所有部分的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM