找出没有主键的表
你知道你的 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 |
+------------------+----------------------------+
| aaa | v_e_loan |
| aaa | v_jx_bill |
| aaa | v_m_cost |
| aaa | v_m_invo |
| bbb | roles |
+------------------+----------------------------+
5 rows in set (0.42 sec)