您的位置:首页 > 数据库 > MySQL

mysql外键索引

2015-08-07 16:42 746 查看
mysql在创建外键的时候会自动添加索引,oracle就不会,这样避免了死锁的产生,提高查询效率

mysql> create table f(id int primary key);

Query OK, 0 rows affected (0.05 sec)

mysql> create table c(id int , foreign key(id) references f(id));

Query OK, 0 rows affected (0.02 sec)

mysql> show index from c;

+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+--------

-------+

| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_c

omment |

+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+--------

-------+

| c     |          1 | id       |            1 | id          | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |

       |

+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+--------

-------+

1 row in set (0.00 sec)

mysql> drop index id on c;

ERROR 1553 (HY000): Cannot drop index 'id': needed in a foreign key constraint

mysql>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: