只删除外键约束的名字不能直接删除外键约束吧,索引一起删才能彻底删除。????
.............
.............
2018-06-07
mysql> SHOW CREATE TABLE tdb_goods; +-----------+------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------+ | Table | Create Table | +-----------+------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------+ | tdb_goods | CREATE TABLE `tdb_goods` ( `goods_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `goods_name` varchar(150) NOT NULL, `cate_id` smallint(5) unsigned NOT NULL, `brand_id` smallint(5) unsigned NOT NULL, `goods_price` decimal(15,3) unsigned NOT NULL DEFAULT '0.000', `is_show` tinyint(1) NOT NULL DEFAULT '1', `is_saleoff` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`goods_id`), KEY `brand_id` (`brand_id`), CONSTRAINT `tdb_goods_ibfk_1` FOREIGN KEY (`brand_id`) REFERENCES `tdb_goods_b rands` (`brand_id`) ) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 | +-----------+------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------+ 1 row in set (0.00 sec) mysql> SHOW INDEXES FROM tdb_goods\G; *************************** 1. row *************************** Table: tdb_goods Non_unique: 0 Key_name: PRIMARY Seq_in_index: 1 Column_name: goods_id Collation: A Cardinality: 23 Sub_part: NULL Packed: NULL Null: Index_type: BTREE Comment: Index_comment: *************************** 2. row *************************** Table: tdb_goods Non_unique: 1 Key_name: brand_id Seq_in_index: 1 Column_name: brand_id Collation: A Cardinality: 23 Sub_part: NULL Packed: NULL Null: Index_type: BTREE Comment: Index_comment: 2 rows in set (0.00 sec) ERROR: No query specified mysql> ALTER TABLE tdb_goods DROP FOREIGN KEY tdb_goods_ibfk_1; Query OK, 23 rows affected (0.05 sec) Records: 23 Duplicates: 0 Warnings: 0 mysql> SHOW CREATE TABLE tdb_goods; +-----------+------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ----------------+ | Table | Create Table | +-----------+------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ----------------+ | tdb_goods | CREATE TABLE `tdb_goods` ( `goods_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `goods_name` varchar(150) NOT NULL, `cate_id` smallint(5) unsigned NOT NULL, `brand_id` smallint(5) unsigned NOT NULL, `goods_price` decimal(15,3) unsigned NOT NULL DEFAULT '0.000', `is_show` tinyint(1) NOT NULL DEFAULT '1', `is_saleoff` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`goods_id`), KEY `brand_id` (`brand_id`) ) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 | +-----------+------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ----------------+ 1 row in set (0.01 sec) mysql> SHOW INDEXES FROM tdb_goods; +-----------+------------+----------+--------------+-------------+-----------+-- -----------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | C ardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +-----------+------------+----------+--------------+-------------+-----------+-- -----------+----------+--------+------+------------+---------+---------------+ | tdb_goods | 0 | PRIMARY | 1 | goods_id | A | 23 | NULL | NULL | | BTREE | | | | tdb_goods | 1 | brand_id | 1 | brand_id | A | 23 | NULL | NULL | | BTREE | | | +-----------+------------+----------+--------------+-------------+-----------+-- -----------+----------+--------+------+------------+---------+---------------+ 2 rows in set (0.00 sec) mysql>
举报