简体   繁体   English

SQL Server Adventureworks SalesOrderDetail表主键

[英]SQL Server Adventureworks SalesOrderDetail table primary key

I would like to ask about the actual reason using the field SalesOrderId as part of the primary key. 我想询问使用字段SalesOrderId作为主键一部分的实际原因。 I think that this should be only a foreign key to the table SalesOrderHeader . 我认为这应该只是表SalesOrderHeader的外键。

Thanks in advance 提前致谢

Ok a little about indexes There are mutiple types. 关于索引可以一点点。有多种类型。 There is a clustered index which determines the physical order the data has on the disk, without this the table is technically known as a heap. 有一个聚集索引,该索引确定数据在磁盘上的物理顺序,没有这个索引,该表在技术上称为堆。 Access of an large volume of data is inefficient. 大量数据的访问效率很低。 The data is random. 数据是随机的。 Any non clustered index (and statistics about data distribution) will refer to the custered index to access data. 任何非聚集索引(以及有关数据分布的统计信息)都将引用聚集的索引来访问数据。 When an index is built the query optimiser will use indexed columns from the left in order to find data. 建立索引后,查询优化器将使用左侧的索引列来查找数据。 So when there is an index col1, col2, col3 if I am joining, searching or whatever on col1, the index will be used. 因此,如果我要加入,搜索或在col1上进行任何搜索,则当有索引col1,col2,col3时,将使用该索引。 If Im filtering on col1,col2 the same index will be used. 如果对col1,col2进行Im过滤,则将使用相同的索引。 There is little or no penalty for this. 对此几乎没有惩罚。 If my query references col1, col2, col3 ONLY (including where and returned columns etc) the the information to be returned can be acertained by ONLY reading the index, the table its self does not need to be accessed. 如果我的查询仅引用col1,col2,col3(包括where和返回的列等),则可以通过仅读取索引来确定要返回的信息,而无需访问其自身的表。 This is known as a covering index. 这称为覆盖指数。 So this is very quick. 所以这很快。 In general, tables should be narrow, indexes wide. 通常,表应该很窄,索引应该很宽。 To find out more I recommend http://www.insidesqlserver.com/thebooks.html Kalen Delany: she knows the SQL dev team personally and writes very clearly. 要了解更多信息,我建议http://www.insidesqlserver.com/thebooks.html Kalen Delany:她个人了解SQL开发团队,并且写得很清楚。 The basic principles are still true from SQL7 through to SQL2012 - although sparce indexes, spatial data types, BI and a lot of other goodies have been added. 从SQL7到SQL2012的基本原理仍然适用-尽管已添加了稀疏索引,空间数据类型,BI和许多其他功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM