【问题标题】:Query to find rowcount of a table查询以查找表的行数
【发布时间】:2016-11-22 23:59:09
【问题描述】:

我正在尝试查找查询以从每个后端数据库中查找表的行数和字节数:

I) MySQL
二)甲骨文数据库
三)SQL Server
IV) Mongo DB
五) 太极数据

【问题讨论】:

  • 你有什么问题,你有什么?
  • 现在对 MySQL、oracl 和 sql server 有正确的方向。在 MySQL、sql server、mongodb 和 Teradata 中寻找正确的查询。我正在寻找可以从表统计中获取这些信息的查询。

标签: mysql sql-server mongodb oracle11g database


【解决方案1】:

#1 的答案是show table statusselect table_name, table_rows from information_schema.tables

【讨论】:

  • 从它提供的整个信息列表中,我如何专门检索单独的行数?
  • 谢谢。检查是否正确:select table_name, table_Rows, data_length from information_Schema.tables where table_name='XXX';
【解决方案2】:

MySQL

Row count of single table

select count(*) from table_name;

Row Count of all tables

SELECT SUM(TABLE_ROWS) 
     FROM INFORMATION_SCHEMA.TABLES 
     WHERE TABLE_SCHEMA = 'database schema name';

Size
SELECT table_schema as `Database`, 
     table_name AS `Table`, 
     round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` 
FROM information_schema.TABLES 
ORDER BY (data_length + index_length) DESC;

大小的结果是这样的

Database Table              Size in MB
sakai    sakai_realm_rl_fn  22.39
sonar    file_sources       8.56
sakai    sakai_site_tool    4.55
sakai    sakai_event        4.03
sonar    issues             3.75
sakai    sakai_site_page    3.03
sonar    project_measures   2.03

MongoDB 在 mongoDB 中我们没有行和列,但一切都是文档,所以我们可以找到一个集合中文档的数量和它的大小。

db.collection.stats() // example db.stackoverflow.stats(), where stackoverflow is my collection name

结果将与此类似

{
        "ns" : "test.stackoverflow",
      "count" : 2,
        "size" : 224,
        "avgObjSize" : 112,
        "numExtents" : 1,
      "storageSize" : 8192,
        "lastExtentSize" : 8192,
        "paddingFactor" : 1,
        "paddingFactorNote" : "paddingFactor is unused and unmaintained in 3.0. It remains hard coded to 1.0 for compatibility only.",
        "userFlags" : 1,
        "capped" : false,
        "nindexes" : 1,
        "totalIndexSize" : 8176,
        "indexSizes" : {
                "_id_" : 8176
        },
        "ok" : 1
}


db.stats(); // Will help us in finding the total documents in the database

Executing it in mongo shell, will a give a result like this

{
        "db" : "test",
        "collections" : 9,
        "objects" : 1000063,
        "avgObjSize" : 112.00058396321032,
        "dataSize" : 112007640,
        "storageSize" : 175837184,
        "numExtents" : 20,
        "indexes" : 12,
        "indexSize" : 169938160,
        "fileSize" : 2080374784,
        "nsSizeMB" : 16,
        "extentFreeList" : {
                "num" : 70,
                "totalSize" : 760217600
        },
        "dataFileVersion" : {
                "major" : 4,
                "minor" : 22
        },
        "ok" : 1
}

这里的 objects 是集合中的文档数

更多信息 - http://docs.mongodb.com/manual/reference/method/db.stats

甲骨文

Row count of single table
select count(*) from table_name

Total Size
select * from dba_data_files;

select round((sum(bytes)/1048576/1024),2) from v$datafile;

To execute these queries you need to login as system user with all priveleges

【讨论】:

  • 完美!如何从 mongodb 统计信息中选择存储大小和计数?
  • db.stats(),将帮助我们在数据库中找到跨集合的总文档 - 在答案部分更新相同
猜你喜欢
  • 1970-01-01
  • 2012-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多