Heim >Datenbank >MySQL-Tutorial >mysql统计一张表中条目个数的方法_MySQL

mysql统计一张表中条目个数的方法_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:02:191192Durchsuche

统计一张表中条目的个通常的SQL语句是:

select count(*) from tableName;

#or
select count(<strong>1</strong>) from tableName;
#or 统计一个列项,如ID
select count(ID)

另外,可通过使用information_schema统计个数

MySQL中有一个名为 information_schema 的数据库,在该库中有一个 TABLES 表,这个表主要字段分别是:

TABLE_SCHEMA : 数据库名

TABLE_NAME:表名

ENGINE:所使用的存储引擎

TABLES_ROWS:记录数

DATA_LENGTH:数据大小

INDEX_LENGTH:索引大小

下面的SQL语句给出了查询方法,同时也统计出了占用存储空间的信息:

复制代码
SELECT information_schema.`TABLES`.TABLE_NAME,
       (DATA_LENGTH/<strong>1024</strong>/<strong>1024</strong>) as DataM ,
    (INDEX_LENGTH/<strong>1024</strong>/<strong>1024</strong>) as IndexM, 
    ((DATA_LENGTH+INDEX_LENGTH)/<strong>1024</strong>/<strong>1024</strong>) as AllM,
    TABLE_ROWS
from information_schema.`TABLES` 
where information_schema.`TABLES`.TABLE_SCHEMA=&#39;abc&#39;;
复制代码
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn