• 查询所有库中表未使用主键的信息


    查询表中未使用主键的表。

    mysql> use information_schema
    Database changed
    mysql> desc tables;
    +-----------------+---------------------+------+-----+---------+-------+
    | Field | Type | Null | Key | Default | Extra |
    +-----------------+---------------------+------+-----+---------+-------+
    | TABLE_CATALOG | varchar(512) | NO | | | |
    | TABLE_SCHEMA | varchar(64) | NO | | | |
    | TABLE_NAME | varchar(64) | NO | | | |
    | TABLE_TYPE | varchar(64) | NO | | | |
    | ENGINE | varchar(64) | YES | | NULL | |
    | VERSION | bigint(21) unsigned | YES | | NULL | |
    | ROW_FORMAT | varchar(10) | YES | | NULL | |
    | TABLE_ROWS | bigint(21) unsigned | YES | | NULL | |
    | AVG_ROW_LENGTH | bigint(21) unsigned | YES | | NULL | |
    | DATA_LENGTH | bigint(21) unsigned | YES | | NULL | |
    | MAX_DATA_LENGTH | bigint(21) unsigned | YES | | NULL | |
    | INDEX_LENGTH | bigint(21) unsigned | YES | | NULL | |
    | DATA_FREE | bigint(21) unsigned | YES | | NULL | |
    | AUTO_INCREMENT | bigint(21) unsigned | YES | | NULL | |
    | CREATE_TIME | datetime | YES | | NULL | |
    | UPDATE_TIME | datetime | YES | | NULL | |
    | CHECK_TIME | datetime | YES | | NULL | |
    | TABLE_COLLATION | varchar(32) | YES | | NULL | |
    | CHECKSUM | bigint(21) unsigned | YES | | NULL | |
    | CREATE_OPTIONS | varchar(255) | YES | | NULL | |
    | TABLE_COMMENT | varchar(2048) | NO | | | |
    +-----------------+---------------------+------+-----+---------+-------+
    21 rows in set (0.00 sec)

    mysql> desc columns;
    +--------------------------+---------------------+------+-----+---------+-------+
    | Field | Type | Null | Key | Default | Extra |
    +--------------------------+---------------------+------+-----+---------+-------+
    | TABLE_CATALOG | varchar(512) | NO | | | |
    | TABLE_SCHEMA | varchar(64) | NO | | | |
    | TABLE_NAME | varchar(64) | NO | | | |
    | COLUMN_NAME | varchar(64) | NO | | | |
    | ORDINAL_POSITION | bigint(21) unsigned | NO | | 0 | |
    | COLUMN_DEFAULT | longtext | YES | | NULL | |
    | IS_NULLABLE | varchar(3) | NO | | | |
    | DATA_TYPE | varchar(64) | NO | | | |
    | CHARACTER_MAXIMUM_LENGTH | bigint(21) unsigned | YES | | NULL | |
    | CHARACTER_OCTET_LENGTH | bigint(21) unsigned | YES | | NULL | |
    | NUMERIC_PRECISION | bigint(21) unsigned | YES | | NULL | |
    | NUMERIC_SCALE | bigint(21) unsigned | YES | | NULL | |
    | DATETIME_PRECISION | bigint(21) unsigned | YES | | NULL | |
    | CHARACTER_SET_NAME | varchar(32) | YES | | NULL | |
    | COLLATION_NAME | varchar(32) | YES | | NULL | |
    | COLUMN_TYPE | longtext | NO | | NULL | |
    | COLUMN_KEY | varchar(3) | NO | | | |
    | EXTRA | varchar(30) | NO | | | |
    | PRIVILEGES | varchar(80) | NO | | | |
    | COLUMN_COMMENT | varchar(1024) | NO | | | |
    | GENERATION_EXPRESSION | longtext | NO | | NULL | |
    +--------------------------+---------------------+------+-----+---------+-------+
    21 rows in set (0.00 sec)

    mysql> select

        -> table_schema,table_name

        -> from

        -> information_schema.tables

        -> where

        -> table_name not in (select distinct table_name from information_schema.columns

        ->  where column_key='pri') and table_schema not in ('mysql','information_schema','sys','performance_schema');

    +--------------+----------------------+

    | table_schema | table_name           |

    +--------------+----------------------+

    | employees    | current_dept_emp     |

    | employees    | dept_emp_latest_date |

    | qq           | a                    |

    | qq           | a1                   |

    | qq           | andyh                |

    | qq           | b                    |

    | qq           | c                    |

    | qq           | d_a                  |

    | qq           | e                    |

    | qq           | myqq                 |

    | qq           | q_s                  |

    | qq           | ttt                  |

    | qq           | vIEW_s               |

    +--------------+----------------------+

    13 rows in set (0.06 sec)

    mysql>

  • 相关阅读:
    CentOS 7 最小化安装建议安装包
    何为“精通Java”
    初识设计模式、软件设计的六大原则
    Git——常用场景解析
    元素水平或垂直居中问题
    书写静态页面的那些事儿。。。
    Position定位相关知识了解
    溢出处理、盒子模型、背景图片、float(浮动)
    CSS颜色、单位、文本样式
    CSS样式表及选择器相关内容(二)-伪类与伪元素选择器
  • 原文地址:https://www.cnblogs.com/chinaops/p/9791433.html
Copyright © 2020-2023  润新知