指定外键是否使它成为索引? [英] Does specifying a foreign key make it an index?

查看:23
本文介绍了指定外键是否使它成为索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表 T,有一个主键 id 和一个外键 f.f 指定为外键时是否自动索引?我需要为 f 显式添加索引吗?

I have a table T with a primary key id and foreign key f. Is f automatically indexed when it is specified as a foreign key? Do I need explicitly add an index for f ?

推荐答案

没有创建索引,所以是的,您需要显式添加添加索引.

No index is created so yes, you need add explicitly add an index.

编辑添加...我可能应该补充一点,表 T 中数据的源表/列必须具有唯一索引.如果您尝试对不是唯一索引的列进行 FK(作为 PK 或具有 UNIQUE 约束),则无法创建 FK.

Edited to add... I probably ought to add that the source table/column for the data in table T must have a unique index. If you try and make an FK to a column that isn't a unique index (either as a PK or with a UNIQUE constraint), the FK can't be created.

这篇关于指定外键是否使它成为索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆