2014-11-04 7 views
0

시나리오 : 10 개 이상의 테이블이있는 데이터베이스가있는 Android 애플리케이션. 서버에서 sq-lite (모바일) 데이터베이스로 데이터를 가져와 저장해야합니다. 이 작업을 효율적으로 수행하기 위해 각 테이블의 행 크기를 계산할 계획이었습니다. 길이는 속성에 할당됩니다.mysql을 사용하여 테이블 크기 추정

---------------------------------------------------------------------------------- 
| 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

I 같은

테이블의 크기를 표시하는 쿼리를 발견 실제로 각 행의 크기를 알아야한다고 생각하지 않습니다. 표의 크기를 총 레코드 수로 나눠서 평균을 계산할 수 있습니다.

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;