欢迎投稿

今日深度:

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

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


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

select count(*) from tableName;

#or
select count(1) 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/1024/1024) as DataM ,
    (INDEX_LENGTH/1024/1024) as IndexM, 
    ((DATA_LENGTH+INDEX_LENGTH)/1024/1024) as AllM,
    TABLE_ROWS
from information_schema.`TABLES` 
where information_schema.`TABLES`.TABLE_SCHEMA='abc';
复制代码

mysql中统计一张表中,不同status的行的个数

select status,count(*) from table group by status
 

一个统计数据库 所有表的记录条数的总与的语句(mysql)

<?php
mysql_connect('localhost','数据库帐号','数据库密码');
mysql_select_db('数据库名');

$result = mysql_query('show tables'); //获取所有表名

$all_record = 0;
while($record = mysql_fetch_row($result)) {
$tb_name = $record[0]; //表名

$n = mysql_result(mysql_query('select count(*) from `'.$tb_name.'`'),0);
$all_record+=$n;
}

echo $all_record; //总记录数

?>
 

www.htsjk.Com true http://www.htsjk.com/shujukunews/3048.html NewsArticle mysql统计一张表中条目个数的方法,mysql条目 统计一张表中条目的个通常的SQL语句是: select count ( * ) from tableName; #or select count ( 1 ) from tableName;# or 统计一个列项,如ID select count (ID) 另外...
相关文章
    暂无相关文章
评论暂时关闭