简体   繁体   English

主键-DB2中的主索引与主键-SQL中的聚集索引

[英]Primary key -Primary Index in DB2 Vs Primary Key - Clustered index in SQL

Primary Index in DB2 Vs Clustered index in SQL. DB2 Vs中的主索引与SQL中的聚集索引。 While migrating db2 to SQL i came to know that primary key in db2 is creating primary index not clustered index. 在将db2迁移到SQL时,我知道db2中的主键正在创建主索引,而不是聚集索引。

I found primary index is different from clustered index in DB2 is it correct? 我发现主索引与DB2中的聚簇索引不同吗? In that case which index we need to use in SQL? 在那种情况下,我们需要在SQL中使用哪个索引?

A SQL Server Clustered Index is basically like the following index in DB2 SQL Server聚集索引基本上类似于DB2中的以下索引

CREATE INDEX ... ON ... (pk-columns) INCLUDE (all-other-columns)

Ie it is useful if your main use of this index is to fetch by the pk-columns and select many other columns. 即,如果该索引的主要用途是通过pk列获取并选择许多其他列,则该功能很有用。

As this index contains all columns, there is no separate table structure (no heap table) for SQL Server tables that have a clustered index. 由于此索引包含所有列,因此对于具有聚集索引的SQL Server表,没有单独的表结构(没有堆表)。

IMHO the clustered index is heavily over used in SQL Server. 恕我直言,聚簇索引在SQL Server中被大量使用。 I wrote this article to explain one problem clustered indexes introduce: 我写这篇文章来解释聚簇索引引入的一个问题:

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

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