方案: 拥有超过十个表的数据库的Android应用程序。 必须从服务器获取数据并将其存储到sq-lite(移动)数据库。 为了有效地执行此操作,我计划计算每个表的行大小。 具有为属性分配的长度。
----------------------------------------------------------------------------------
| table_name | Size of single row with defined attributes length |
|----------------------------------------------------------------------------------|
| table_1 | size |
|----------------------------------------------------------------------------------|
| table_2 | size |
|----------------------------------------------------------------------------------|
| table_3 | size |
----------------------------------------------------------------------------------
是否有任何mysql查询计算表格在创建时分配给属性的长度的单行长度?
就像我找到了显示表格大小的查询:
SELECT table_name AS "Table",
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = "$DB_NAME"
AND table_name = "$TABLE_NAME";
或此查询列出数据库中每个表的大小,最大的第一个:
SELECT table_name AS "Tables",
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = "$DB_NAME"
ORDER BY (data_length + index_length) DESC;
答案 0 :(得分:0)
我不相信你真的需要知道每一行的大小。您可以通过将表的大小除以记录总数来计算它们的平均值。
select count(*) into @tableRecordCount from table_name;
select table_name as "Tables".
round(((data_length + index_length) / (1024 * 1024 * @tableRecordCount), 2) "Size in MB per record"
from information_schema.TABLES
where table_schame = "$DB_NAME"
order by (data_length + index_length) desc;