Row Locator in Non Clustered Index

北城余情 提交于 2019-12-04 15:04:13

If the table has a unique clustered index, the "row locator" consists of the columns of the clustered index.

With a non-unique clustered index, the "row locator" consists of the columns of the clustered index, plus a new field SQL Server adds to make the reference unique. The new field is invisible to users. It's called "uniqueifier" and consists of four bytes.

In a table without a clustered index (aka a heap), the "row locator" is a RID or row identifier. The RID points to a physical location. It consists of the file identifier (ID), page number, and number of the row on the page.

One practical consequence of the "row locator" is that it makes sense to have a small primary key for a table with a lot of indexes :) Full details on this MSDN page.

@Nilish: "Candidate key" is a term used when you are deciding which column(s) to use for the primary key. And SQL doesn't know anything about that. I don't know what "alternate key" means except that it's another possible set of columns to use for a primary key.

So, there is no concept of "priorities" for these within SQL. SQL doesn't know which columns uniquely identify the record until you tell it by creating a primary key. Once you define the keys, then SQL uses them.

A table has either no indexes (a heap), or a non-unique clustered index, or a unique clustered index. There are no other possibilities. (The primary key is USUALLY a unique clustered index.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!