zoukankan      html  css  js  c++  java
  • 010.mysql-mysql查询表注释、字段、备注、大小、存储过程

    查询字段注释

    查询表注释字段注释
    

    SELECT
    a.TABLE_SCHEMA 库名,
    a.table_name 表名,
    a.table_comment 表说明,
    b.COLUMN_NAME 字段名,
    b.column_comment 字段说明,
    b.column_type 字段类型,
    b.column_key 约束
    FROM
    information_schema.TABLES a
    LEFT JOIN information_schema.COLUMNS b

    
    

    ON a.table_name = b.TABLE_NAME and a.TABLE_SCHEMA = b.TABLE_SCHEMA
    WHERE
    a.TABLE_SCHEMA = 'qhdata_warehouse_north_stat' and a.TABLE_NAME LIKE 'dw_ytb_org_finance%'
    ORDER BY
    a.TABLE_SCHEMA,a.table_name

    
    
    
    
    查询数据库名和表名
    SELECT
        TABLE_SCHEMA,TABLE_NAME,TABLE_COMMENT
    FROM
        information_schema.`TABLES`
    WHERE
        TABLE_SCHEMA = 'db_lgdata_ioc'
    AND TABLE_NAME LIKE 'ud_lg_ioc_tech_inovate%'

    查询存储过程

    mysql如何查询所有的存储过程中是否使用到这张表
    判断一个表在哪些存储过程中
    select * from mysql.proc
    where db = 'db_lgstat_ioc' and type = 'PROCEDURE'
    and body like '%s_ls_tjj_qdsjgljlgqqrqymd%'
    
    
    查询所有存储过程,存储过程备份
    -- mysql5以下
    select db, name, CONVERT (body USING utf8)  from mysql.proc
    where db in  ('test') and type = 'PROCEDURE';
    -- mysql 8 
    select ROUTINE_SCHEMA,SPECIFIC_NAME,ROUTINE_DEFINITION from   information_schema.ROUTINES  
    where ROUTINE_TYPE='PROCEDURE'  and ROUTINE_SCHEMA in('qhdata_market') ;
    
    
    mysql8.0写法
    -- ROUTINE_SCHEMA  存储过程库名
    -- ROUTINE_NAME        存储过程名
    -- ROUTINE_DEFINITION    存储过程内容
    select * from   information_schema.ROUTINES  
    where ROUTINE_TYPE='PROCEDURE' 
    and  ROUTINE_DEFINITION like '%dw_lg_ioc_gdzctz_jc%'

    表大小

    第二种:查询所有数据的大小
    select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from information_schema.TABLES
    第三种:查看指定数据库的大小,比如说:数据库apoyl
    select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from information_schema.TABLES where table_schema='apoyl';
    第四种:查看指定数据库的表的大小,比如说:数据库apoyl 中apoyl_test表
    select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from information_schema.TABLES where table_schema='apoyl' and table_name='apoyl_test';

    表容量

    库的每个scheme
    select
    table_schema as '数据库',
    sum(table_rows) as '记录数',
    sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
    sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'
    from information_schema.tables
    group by table_schema
    order by sum(data_length) desc, sum(index_length) desc
    
    
    库的所有
    select 
     sum(记录数)
    ,sum(`数据容量(MB)`)
    ,sum(`索引容量(MB)`)
    from 
    (
    
    select
    table_schema as '数据库',
    sum(table_rows) as '记录数',
    sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
    sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'
    from information_schema.tables
    group by table_schema
    order by sum(data_length) desc, sum(index_length) desc
    
    )b;
  • 相关阅读:
    js/es6判断对象是否为空,并判断对象是否包含某个属性
    Hive中的SQL执行计划--几乎所有的SQL都有
    spark中的scalaAPI之RDDAPI常用操作
    spark-scala开发的第一个程序WordCount
    linux中添加自定义命令
    kafka学习总结
    flume的sink写入hive表
    Flume架构以及应用介绍(转)
    Appache Flume 中文介绍(转)
    hiveSQL常用日期函数
  • 原文地址:https://www.cnblogs.com/star521/p/13640831.html
Copyright © 2011-2022 走看看