如何导出MySQL索引的创建语句

SELECT
CONCAT('ALTER TABLE `',TABLE_NAME,'` ', 'ADD ',
IF( any_value(NON_UNIQUE )= 1,
CASE UPPER(any_value(INDEX_TYPE))
WHEN 'FULLTEXT' THEN 'FULLTEXT INDEX'
WHEN 'SPATIAL' THEN 'SPATIAL INDEX'
ELSE CONCAT('INDEX `',
INDEX_NAME,
'` USING ',
any_value(INDEX_TYPE)
)
END,
IF(UPPER(INDEX_NAME) = 'PRIMARY',
CONCAT('PRIMARY KEY USING ',
any_value(INDEX_TYPE)
),
CONCAT('UNIQUE INDEX `',
INDEX_NAME,
'` USING ',
any_value(INDEX_TYPE)
)
)
),'(', GROUP_CONCAT(DISTINCT CONCAT('`', COLUMN_NAME, '`') ORDER BY SEQ_IN_INDEX ASC SEPARATOR ', '), ');') AS 'Show_Add_Indexes'
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = 'ordercenter' AND TABLE_NAME='order_info_sub'
GROUP BY TABLE_NAME, INDEX_NAME
ORDER BY TABLE_NAME ASC, INDEX_NAME ASC

转载于:https://www.cnblogs.com/iwyc/p/11226066.html

你可能感兴趣的:(如何导出MySQL索引的创建语句)