索引与外键有什么区别? [英] What is the difference between an Index and a Foreign Key?

查看:219
本文介绍了索引与外键有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用3个表创建一个数据库。一个是帖子和一个是标签,另一个是将帖子链接到标签,post_id和tag_id作为外键参考。



你能解释一下索引是什么场景以及它与外键的区别,以及它如何影响我的数据库设计?结构,使随机访问行快速和高效。它有助于优化表的内部组织。

外键只是一个指向另一个表中相应列的指针,它形成了两个表之间的引用约束表。


I want to create a database with 3 tables. One for posts and one for tags and one that links posts to tags with the post_id and tag_id functioning as foreign key references.

Can you explain what an Index would be in this scenario and how it differs from a Foreign Key and how that impacts my database design?

解决方案

an index on a table is a data structure that makes random access to the rows fast and efficient. It helps to optimize the internal organization of a table as well.

A foreign key is simply a pointer to a corresponding column in another table that forms a referential constraint between the two tables.

这篇关于索引与外键有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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