mysql有主健表

mysql有主健表

select * from 
(
SELECT TABLE_NAME,TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA="gooddriver" -----数据库名字
) a LEFT JOIN
(

SELECT
DISTINCT
 concat('ALTER TABLE ' , t.TABLE_NAME , ' ADD INDEX ',c.COLUMN_NAME, ' (' , c.COLUMN_NAME, ') USING BTREE;') mySql,
t.TABLE_NAME ,
  t.CONSTRAINT_TYPE,
  c.COLUMN_NAME,
  c.ORDINAL_POSITION
FROM
  INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS t,
  INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c
WHERE
  t.TABLE_NAME = c.TABLE_NAME
  AND t.TABLE_SCHEMA = 'gooddriver'----数据库名字
  AND t.CONSTRAINT_TYPE = 'PRIMARY KEY'
) b
on a.TABLE_NAME = b.TABLE_NAME

你可能感兴趣的:(mysql)