sql主键和索引 [英] sql primary key and index

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

问题描述

假设我在数据库集中有一个ID行(int)作为主键。如果我经常查询ID,我还需要索引吗?或者它是主键意味着它已被索引?

Say I have an ID row (int) in a database set as the primary key. If I query off the ID often do I also need to index it? Or does it being a primary key mean it's already indexed?

我问的原因是因为在MS SQL Server中我可以在这个ID上创建一个索引,正如我所说的那样我的主键。

Reason I ask is because in MS SQL Server I can create an index on this ID, which as I stated is my primary key.

编辑:一个额外的问题 - 额外索引主键会不会有什么害处?

an additional question - will it do any harm to additionally index the primary key?

推荐答案

你是对的,SQL Server允许你在同一个字段上创建重复索引,这很令人困惑。但你可以创建另一个的事实并不表明PK索引也不存在。

You are right, it's confusing that SQL Server allows you to create duplicate indexes on the same field(s). But the fact that you can create another doesn't indicate that the PK index doesn't also already exist.

附加索引没有好处,但唯一的危害(非常小)是额外的文件大小和行创建开销。

The additional index does no good, but the only harm (very small) is the additional file size and row-creation overhead.

这篇关于sql主键和索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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