亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

mysql表類型查詢示例詳解

 更新時間:2025年04月17日 11:06:47   作者:韶博雅  
這篇文章主要介紹了mysql表類型查詢示例詳解,本文通過實例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧

普通表

SELECT 
    table_schema AS database_name,
    table_name
FROM 
    information_schema.tables
WHERE 
    table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
    AND table_type = 'BASE TABLE'
    AND table_name NOT IN (
        SELECT DISTINCT table_name 
        FROM information_schema.partitions 
        WHERE partition_name IS NOT NULL
    )
ORDER BY 
    table_schema, table_name;

分區(qū)表

SELECT 
    p.table_schema AS database_name,
    p.table_name,
    GROUP_CONCAT(p.partition_name ORDER BY p.partition_ordinal_position) AS partitions,
    p.partition_method,
    p.partition_expression
FROM 
    information_schema.partitions p
WHERE 
    p.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
    AND p.partition_name IS NOT NULL
GROUP BY 
    p.table_schema, p.table_name, p.partition_method, p.partition_expression
ORDER BY 
    p.table_schema, p.table_name;

區(qū)分表

SELECT 
    t.table_schema AS database_name,
    t.table_name,
    CASE 
        WHEN p.table_name IS NULL THEN '普通表'
        ELSE '分區(qū)表'
    END AS table_type,
    p.partition_method,
    p.partition_expression
FROM 
    information_schema.tables t
LEFT JOIN (
    SELECT DISTINCT 
        table_schema, 
        table_name,
        partition_method,
        partition_expression
    FROM 
        information_schema.partitions 
    WHERE 
        partition_name IS NOT NULL
) p ON t.table_schema = p.table_schema AND t.table_name = p.table_name
WHERE 
    t.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
    AND t.table_type = 'BASE TABLE'
ORDER BY 
    t.table_schema, t.table_name;

查出數(shù)據(jù)量

SELECT 
    t.table_schema AS '數(shù)據(jù)庫名',
    t.table_name AS '表名',
    CASE 
        WHEN p.table_name IS NULL THEN '普通表'
        ELSE CONCAT('分區(qū)表(', p.partition_method, ')')
    END AS '表類型',
    t.table_rows AS '數(shù)據(jù)行數(shù)(估算)',
    CONCAT(ROUND(t.data_length / (1024 * 1024), 2), ' MB') AS '數(shù)據(jù)大小',
    CONCAT(ROUND(t.index_length / (1024 * 1024), 2), ' MB') AS '索引大小',
    CONCAT(ROUND((t.data_length + t.index_length) / (1024 * 1024), 2), ' MB') AS '總大小',
    p.partition_expression AS '分區(qū)鍵'
FROM 
    information_schema.tables t
LEFT JOIN (
    SELECT DISTINCT 
        table_schema, 
        table_name,
        partition_method,
        partition_expression
    FROM 
        information_schema.partitions 
    WHERE 
        partition_name IS NOT NULL
) p ON t.table_schema = p.table_schema AND t.table_name = p.table_name
WHERE 
    t.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
    AND t.table_type = 'BASE TABLE'
ORDER BY 
    t.table_schema, 
    CASE WHEN p.table_name IS NULL THEN 0 ELSE 1 END,  -- 普通表在前
    t.table_name;
SELECT 
    t.table_schema AS '數(shù)據(jù)庫',
    t.table_name AS '表名',
    CASE 
        WHEN p.partition_method IS NULL THEN '普通表'
        ELSE CONCAT('分區(qū)表(', p.partition_method, ')')
    END AS '表類型',
    t.table_rows AS '估算行數(shù)',
    CONCAT(ROUND(t.data_length/1024/1024, 2), ' MB') AS '數(shù)據(jù)大小',
    p.partition_expression AS '分區(qū)鍵'
FROM 
    information_schema.tables t
LEFT JOIN (
    SELECT 
        table_schema, 
        table_name,
        partition_method,
        partition_expression
    FROM 
        information_schema.partitions
    WHERE 
        partition_name IS NOT NULL
    GROUP BY 
        table_schema, table_name, partition_method, partition_expression
) p ON t.table_schema = p.table_schema AND t.table_name = p.table_name
WHERE 
    t.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
    AND t.table_type = 'BASE TABLE'
ORDER BY 
    t.table_schema, t.table_name;

查出表行數(shù)

SELECT 
    t.table_schema AS '數(shù)據(jù)庫',
    t.table_name AS '表名',
    CASE 
        WHEN p.partition_method IS NULL THEN '普通表'
        ELSE CONCAT('分區(qū)表(', p.partition_method, ')')
    END AS '表類型',
    t.table_rows AS '估算行數(shù)',
    p.partition_expression AS '分區(qū)鍵'
FROM 
    information_schema.tables t
LEFT JOIN (
    SELECT DISTINCT 
        table_schema, 
        table_name,
        partition_method,
        partition_expression
    FROM 
        information_schema.partitions
    WHERE 
        partition_name IS NOT NULL
) p ON t.table_schema = p.table_schema AND t.table_name = p.table_name
WHERE 
    t.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
    AND t.table_type = 'BASE TABLE'
ORDER BY 
    t.table_schema, t.table_name;

到此這篇關(guān)于mysql表類型查詢的文章就介紹到這了,更多相關(guān)mysql表類型查詢內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 解決MYSQL連接端口被占引入文件路徑錯誤的問題

    解決MYSQL連接端口被占引入文件路徑錯誤的問題

    下面小編就為大家?guī)硪黄鉀QMYSQL連接端口被占引入文件路徑錯誤的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • RedHat6.5/CentOS6.5安裝Mysql5.7.20的教程詳解

    RedHat6.5/CentOS6.5安裝Mysql5.7.20的教程詳解

    這篇文章主要介紹了RedHat6.5/CentOS6.5安裝Mysql5.7.20的教程詳解,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-11-11
  • Windows10下mysql 8.0.16 安裝配置方法圖文教程

    Windows10下mysql 8.0.16 安裝配置方法圖文教程

    這篇文章主要為大家詳細(xì)介紹了Windows10下mysql 8.0.16 安裝配置方法圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • MySql?字符集不同導(dǎo)致?left?join?慢查詢的問題解決

    MySql?字符集不同導(dǎo)致?left?join?慢查詢的問題解決

    當(dāng)兩個表的字符集不一樣,在使用字符型字段進(jìn)行表連接查詢時,就需要特別注意下查詢耗時是否符合預(yù)期,本文主要介紹了MySql?字符集不同導(dǎo)致?left?join?慢查詢的問題解決,感興趣的可以了解一下
    2024-05-05
  • 解決mysql報錯:Data?source?rejected?establishment?of?connection,?message?from?server:?\"Too?many?connectio

    解決mysql報錯:Data?source?rejected?establishment?of?connect

    這篇文章主要給大家介紹了關(guān)于如何解決mysql報錯:Data?source?rejected?establishment?of?connection,?message?from?server:?\"Too?many?connectio的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-02-02
  • MySQL下載安裝詳情圖文教程

    MySQL下載安裝詳情圖文教程

    本文通過圖文并茂的形式給大家介紹了MySQL下載安裝詳情,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-08-08
  • MYSQL使用Union將兩張表的數(shù)據(jù)合并顯示

    MYSQL使用Union將兩張表的數(shù)據(jù)合并顯示

    使用union操作符會將多張表中相同的數(shù)據(jù)取值一次,如果想將表1和表2中的值完整的顯示出來,可以使用union all,今天通過本文給大家分享MYSQL使用Union將兩張表的數(shù)據(jù)合并顯示功能,需要的朋友參考下吧
    2021-08-08
  • 詳解MySQL的主從復(fù)制、讀寫分離、備份恢復(fù)

    詳解MySQL的主從復(fù)制、讀寫分離、備份恢復(fù)

    本篇文章主要對MySQL的主從復(fù)制、讀寫分離、備份恢復(fù)進(jìn)行詳細(xì)全面的講解,具有很好的參考價值,需要的朋友一起來看下吧
    2016-12-12
  • Mysql外鍵設(shè)置中的CASCADE、NO ACTION、RESTRICT、SET NULL

    Mysql外鍵設(shè)置中的CASCADE、NO ACTION、RESTRICT、SET NULL

    本文主要介紹了Mysql外鍵設(shè)置中的CASCADE、NO ACTION、RESTRICT、SET NULL,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • 一文詳解MySQL?Binlog日志與主從復(fù)制

    一文詳解MySQL?Binlog日志與主從復(fù)制

    這篇文章主要介紹了一文詳解MySQL?Binlog日志與主從復(fù)制,Binlog是Binary?log的縮寫,即二進(jìn)制日志,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,需要的朋友可以參考一下
    2022-07-07

最新評論