SQL:如何查找查询返回的总数据大小(以字节为单位)?

时间:2022-04-19 01:28:31

Something like:

SUM(*) FROM orders WHERE 'x' = 1;

This has to be done from SQL itself, as this will be part of larger query.

这必须从SQL本身完成,因为这将是更大的查询的一部分。

The purpose of this is to review the storage size and check on possible savings by deleting obsolete data.

这样做的目的是通过删除过时的数据来检查存储大小并检查可能的节省。

SQL Server has some handy stored procedures for this. This is MySQL DB, so I'm looking a generic SQL solution as possible, short of that, something for MySql

SQL Server有一些方便的存储过程。这是MySQL DB,所以我正在寻找一个通用的SQL解决方案,简而言之,MySql的东西

1 个解决方案

#1


3  

Why not use count?

为什么不使用计数?

SELECT count(*) FROM orders WHERE 'x' =1

Alternatively, you can use the information schema table:

或者,您可以使用信息架构表:

SELECT TABLE_NAME ,
       (DATA_LENGTH/ 1024) AS "Data Length in MB",
       (INDEX_LENGTH / 1024) AS "Index Length in MB"
       FROM INFORMATION_SCHEMA.TABLES 
       WHERE TABLE_SCHEMA = 'YOUR DATABASE NAME' 
       AND
       TABLE_NAME = 'YOUR TABLE NAME';

Where 'YOUR DATABASE NAME' is your database's name, and 'YOUR TABLE NAME' is the table you need to know data about.

“您的数据库名称”是您的数据库名称,“您的表名称”是您需要了解数据的表。

#1


3  

Why not use count?

为什么不使用计数?

SELECT count(*) FROM orders WHERE 'x' =1

Alternatively, you can use the information schema table:

或者,您可以使用信息架构表:

SELECT TABLE_NAME ,
       (DATA_LENGTH/ 1024) AS "Data Length in MB",
       (INDEX_LENGTH / 1024) AS "Index Length in MB"
       FROM INFORMATION_SCHEMA.TABLES 
       WHERE TABLE_SCHEMA = 'YOUR DATABASE NAME' 
       AND
       TABLE_NAME = 'YOUR TABLE NAME';

Where 'YOUR DATABASE NAME' is your database's name, and 'YOUR TABLE NAME' is the table you need to know data about.

“您的数据库名称”是您的数据库名称,“您的表名称”是您需要了解数据的表。