为什么主键顺序很重要?

编程入门 行业动态 更新时间:2024-10-11 23:19:41
本文介绍了为什么主键顺序很重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我最近在EntityFramework项目中设置了一个类,它将一个组合键指定为一个组合键。

I recently set up a class in an EntityFramework project which designated a couple of its members as a composite key.

然而,当它创建时数据库从它它给出错误

However, when it came to time to create the database from this it gave the error

无法确定类型NNNNN的复合主键排序。使用ColumnAttribute或HasKey方法来指定复合主键的顺序。

Unable to determine composite primary key ordering for type 'NNNNN'. Use the ColumnAttribute or the HasKey method to specify an order for composite primary keys.

我知道如何解决问题,但我是只是想知道为什么它关心订单。不是一个复合主键,只是一组列,在其上键入记录,而不需要任何特定的排序?

I know how to solve the problem, but I was just wondering why it cares about the order. Isn't a composite primary key just a set of columns on which to key the records, without any particular ordering necessary?

推荐答案

这很重要,因为主键的顺序在数据库中很重要。由于主键(通常)是集群的,并且始终是索引,无论密钥是按名字,姓氏,SSN或SSN,姓氏,名字排序都会产生巨大的差异。如果我在查询表时只有SSN,而PK是唯一的索引,那么我将看到后者具有很高的性能,而前者将扫描完整的表。

It matters because the order of primary keys matter in the database. Since primary keys are (usually) clustered, and always indices, whether the key is ordered as First Name, Last Name, SSN or SSN, Last Name, First Name, makes a huge difference. If I only have the SSN when I'm querying the table, and the PK is the only index, I'll see GREAT performance with the latter, and a full table scan with the former.

更多推荐

为什么主键顺序很重要?

本文发布于:2023-11-02 18:21:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1553087.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:很重要   主键   顺序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!