• MySQL元数据操作:查询 MySQL 空表,拥有某字段的表,等


    1、查询MySQL库下所有表名,数据不为空的表,反之查询为空的表

    SELECT
        table_name,
        table_rows
    FROM
        information_schema. TABLES
    WHERE
        table_schema = 'ahbo'
    AND table_rows < 1;

     

    2、查询指定库拥有某字段的表

    SELECT DISTINCT
        TABLE_NAME
    FROM
        information_schema. COLUMNS
    WHERE
        COLUMN_NAME = 'columnName'
    AND TABLE_SCHEMA = 'dbName'
    AND TABLE_NAME NOT LIKE 'vw%';

    3、修改指定数据库中所有varchar类型的表字段的字符集为UTF8,并将排序规则修改为utf8_general_ci

    SELECT CONCAT('ALTER TABLE `', table_name, '` MODIFY `', column_name, '` ', DATA_TYPE, '(', CHARACTER_MAXIMUM_LENGTH, ') CHARACTER SET UTF8 COLLATE utf8_general_ci', (CASE WHEN IS_NULLABLE = 'NO' THEN ' NOT NULL' ELSE '' END), ';')
    别名
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = 'SchoolUserOnline_20170416'
    AND DATA_TYPE = 'varchar'
    AND
    (
        CHARACTER_SET_NAME != 'utf8'
        OR
        COLLATION_NAME != 'utf8_general_ci'
    );

    4、修改指定数据库中所有数据表的字符集为UTF8,并将排序规则修改为utf8_general_ci

    SELECT CONCAT('ALTER TABLE ', table_name, ' CONVERT TO CHARACTER SET  utf8 COLLATE utf8_unicode_ci;')
    FROM information_schema.TABLES
    WHERE TABLE_SCHEMA = 'databaseName'
    源码,是痛苦的,又是快乐的,如果没有这痛苦,也就没有了这快乐!
  • 相关阅读:
    扩展Dijkstra
    CodeForces 1396E. Distance Matching
    大联盟2
    整式乘除法
    美国数学会众多教授推荐的本科&研究生代数几何经典书籍教材清单
    算法题——立方体的体对角线穿过多少个正方体?
    导数练习题
    导数压轴题
    集合
    著名数学家Ky Fan的故事
  • 原文地址:https://www.cnblogs.com/erlongxizhu-03/p/14299368.html
Copyright © 2020-2023  润新知