An index is used to speed up searching in the database.

By default, when you create this table, your data will be stored on disk and sorted by the "Id" primary key column. This default sort is called the "Clustered Index".

  • Affects the physical order of data so there can only one clustered index.

With a clustered index the rows are stored physically on the disk in the same order as the index. There can therefore be only one clustered index.

But if you search by other non-primary key columns most of the time on this table, then you might want to consider changing the clustered index to this column instead.

There a few things to keep in mind when changing the default clustered index in a table:

  1. Lookups from non-clustered indexes must look up the query pointer in the clustered index to get the pointer to the actual data records instead of going directly to the data on disk (usually this performance hit is negligble).
  2. Inserts will be slower because the insert must be added in the exact right place in the clustered index. (NOTE: This does not re-order the data pages. It just inserts the record in the correct order in the page that it corresponds to. Data pages are stored as doubly-linked lists so each page is pointed to by the previous and next. Therefore, it is not important to reorder the pages, just their pointers and that is only in the case where the newly inserted row causes a new data page to be created.)

Non-clustered indexes are not copies of the table but a sorting of the columns you specify that "point" back to the data pages in the clustered index. With a non clustered index there is a second list that has pointers to the physical rows. You can have many non clustered indexes, although each new index will increase the time it takes to write new records.

It is generally faster to read from a clustered index if you want to get back all the columns. You do not have to go first to the index and then to the table.

Writing to a table with a clustered index can be slower, if there is a need to rearrange the data.

小总:Clustered index意思是在选取某个column A,以它排序来存储table里的所有records,所以当你以A为选择条件来做query的时候,因为physically records locate in the same order as the index,通过clustered index可以很快找到符合条件的records。

Non-clustered index意思是比如还是column A,index会存储A的值以及a pointer to the in the table where that value is actually stored.而clusterd index会在leaf node里存储整条record。所以clustered index会更快。

[SQL Basics] Indexes的更多相关文章

  1. Some SQL basics

    1, Index An index is a set of data pointers stored on disk associated with a single table. The main ...

  2. Azure SQL Database (19) Stretch Database 概览

    <Windows Azure Platform 系列文章目录>  Azure SQL Database (19) Stretch Database 概览      Azure SQL Da ...

  3. SQL Server 堆表行存储大小(Record Size)

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 堆表行记录存储格式(Heap) 案例分析(Case) 参考文献(References) 二.背 ...

  4. 【译】SQL Server索引进阶第八篇:唯一索引

    原文:[译]SQL Server索引进阶第八篇:唯一索引     索引设计是数据库设计中比较重要的一个环节,对数据库的性能其中至关重要的作用,但是索引的设计却又不是那么容易的事情,性能也不是那么轻易就 ...

  5. SQL Server索引进阶:第十级,索引内部结构

    原文地址: Stairway to SQL Server Indexes: Level 10,Index Internal Structure 本文是SQL Server索引进阶系列(Stairway ...

  6. SQL Server索引进阶:第九级,读懂执行计划

    原文地址: Stairway to SQL Server Indexes: Level 9,Reading Query Plans 本文是SQL Server索引进阶系列(Stairway to SQ ...

  7. SQL Server索引进阶:第八级,唯一索引

    原文地址: Stairway to SQL Server Indexes: Level 8,Unique Indexes 本文是SQL Server索引进阶系列(Stairway to SQL Ser ...

  8. SQL Server索引进阶:第七级,过滤的索引

    原文地址: Stairway to SQL Server Indexes: Level 7,Filtered Indexes 本文是SQL Server索引进阶系列(Stairway to SQL S ...

  9. SQL Server索引进阶:第六级,标签

    原文地址: Stairway to SQL Server Indexes: Level 6,Bookmarks 本文是SQL Server索引进阶系列(Stairway to SQL Server I ...

随机推荐

  1. 如何做个简单安卓App流程

    有同学做毕业设计,问怎样做个简单安卓App流程,我是做服务端的,也算是经常接触app,想着做app应该很简单吧,不就做个页面,会跳转,有数据不就行了,我解释了半天,人家始终没听懂,算了,我第二天问了下 ...

  2. WPFの静态资源(StaticResource)和动态资源(DynamicResource)

    下面是前台代码: <Window.Resources>        <TextBlock x:Key="res1" Text="好好学习"/ ...

  3. 解决安装完centos6.6之后/etc/sysconfig/目录下没有iptables 的问题

    我在安装完成centos6.6之后对防火墙进行配置,但是发现在/etc/sysconfig目录下没有iptables,心里犯嘀咕,随后就写了一条命令,保存下试试,谁知道成功了! 如图 没有发现ipta ...

  4. (转)awk实例练习(一)

    文章转自 http://www.cnblogs.com/zhuyp1015/archive/2012/07/14/2591822.html 前一篇学习了awk的基本知识,现在来做一些练习加深一下印象. ...

  5. IIS7配置PHP运行环境

    1.下载PHP运行包,网址:http://windows.php.net/download/ 选择的对应的版本包下载,并解压到相应的目录中(不限定),如:E:\vss\php\php_sdk 2.配置 ...

  6. 《BI项目笔记》历年外观质量均值变化分析Cube的建立

    分析主题主要维度:烟叶级别.烟叶级别按等级信息.烟叶级别按分级标准(标准维度)产地(父子维度)检测时间(时间维度,以Tqc_Raw_PresentationQuality . CheckTime字段派 ...

  7. 从webRoot中下载Excel

    @RequestMapping("downLoad") public void downLoad(Offsupervise off1,HttpServletRequest requ ...

  8. JavaScript中的String

    1.基本类型String var str ="helloworld"; 要记住:保存的是Unicode字符,一旦创建便不可变   2.引用类型String var strObj = ...

  9. Google Protocol Buffer的安装与.proto文件的定义

    什么是protocol Buffer呢? Google Protocol Buffer( 简称 Protobuf) 是 Google 公司内部的混合语言数据标准. 我理解的就是:它是一种轻便高效的结构 ...

  10. MemCache的LRU删除机制详解

    本节主要讲解一下MC的LRU的删除机制和一些参数的限制 MC的过期数据惰性删除 1.当某个值过期后,并没有从内存中删除,因此,我们在进行st ats统计信息的时候,curr_items有其信息(它的数 ...