日期:2014-05-16  浏览次数:20883 次

mysql清除外键

清除所有外键:set foreign_key_checks=0;
逐个清除外键:alter table tbname drop foreign key foreign_key_name

?

SELECT
CONCAT(' ALTER TABLE ',TABLE_CONSTRAINTS.CONSTRAINT_SCHEMA,'.',TABLE_CONSTRAINTS.TABLE_NAME,'? DROP FOREIGN KEY? ',TABLE_CONSTRAINTS.CONSTRAINT_NAME,';')
FROM
TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
AND CONSTRAINT_SCHEMA IN ('ecshop')

?

MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html