为了账号安全,请及时绑定邮箱和手机立即绑定

只删除外键约束的名字不能直接删除外键约束吧,索引一起删才能彻底删除。????

.............

正在回答

5 回答

1、查看表结构,有外键

2、查看INDEXES,有外键索引

3、删除外键,查看表结构发现没有外键,查看索引发现外键索引还在。

没有发现你这种情况:

“我只删除名字 查看表结构时还是显示有外键啊????                                ”

0 回复 有任何疑惑可以回复我~
#1

qq_简简单单_119 提问者

非常感谢!
2018-06-14 回复 有任何疑惑可以回复我~

https://img1.sycdn.imooc.com//5b2220a90001047006390917.jpg我删了名字  表结构中PID列的key还是MUL

0 回复 有任何疑惑可以回复我~
#1

叶0528

索引没有删。PRI主键约束; UNI唯一约束; MUL可以重复。
2018-06-19 回复 有任何疑惑可以回复我~
#2

叶0528

mysql中如何设置某字段Key 为MUL:加个索引INDEX https://blog.csdn.net/chenxieyy/article/details/70241382
2018-06-19 回复 有任何疑惑可以回复我~
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>


0 回复 有任何疑惑可以回复我~
#1

qq_简简单单_119 提问者

你看一下我下一个回答我的意思是这个 , 搞不懂为什么。
2018-06-14 回复 有任何疑惑可以回复我~

只删除外键约束的名字能直接删除外键约束,

但是这个外键的索引还在。

添加外键约束的时候会自动添加其索引。


0 回复 有任何疑惑可以回复我~
#1

qq_简简单单_119 提问者

我只删除名字 查看表结构时还是显示有外键啊????
2018-06-08 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
与MySQL的零距离接触
  • 参与学习       397028    人
  • 解答问题       3350    个

本课程涵盖全部MySQL数据库的基础,学习MySQL数据库的基础知识

进入课程

只删除外键约束的名字不能直接删除外键约束吧,索引一起删才能彻底删除。????

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信