获取缺失主键表信息的MYSQL语句
编程学习 2021-07-05 15:27www.dzhlxh.cn编程入门
如何获取缺失主键表信息,想必有些朋友还是不会的吧,狼蚁网站SEO优化为大家介绍下,可以通过几条语句实现,感兴趣的朋友可以了解下
代码如下:
SELECT a.`TABLE_SCHEMA` AS DB_NAME , a.`TABLE_NAME` , a.`TABLE_ROWS` ,a.`ENGINE` -- , a.*
FROM
information_schema.`TABLES` a
LEFT JOIN information_schema.`TABLE_CONSTRAINTS` b
ON a.`TABLE_NAME` = b.`TABLE_NAME` AND a.`TABLE_SCHEMA` = b.`TABLE_SCHEMA`
WHERE b.`TABLE_SCHEMA` IS NULL
AND a.`TABLE_TYPE` = 'BASE TABLE'
AND a.`TABLE_SCHEMA` NOT IN ('information_schema','test','mysql','performance_schema')
ORDER BY DB_NAME ,a.`TABLE_ROWS` DESC ;