Reputation: 504
Just for knowledge in interview question, and my knowledge.
SQL - Difference between Cluster
and Non-cluster index
?
Upvotes: 6
Views: 14478
Reputation: 154
Indexes are used to speed-up query process in SQL Server, resulting in high performance. They are similar to textbook indexes. In textbooks, if you need to go to a particular chapter, you go to the index, find the page number of the chapter and go directly to that page. Without indexes, the process of finding your desired chapter would have been very slow.
The same applies to indexes in databases. Without indexes, a DBMS has to go through all the records in the table in order to retrieve the desired results. This process is called table-scanning and is extremely slow. On the other hand, if you create indexes, the database goes to that index first and then retrieves the corresponding table records directly.
There are two types of Indexes in SQL Server:
Clustered Index
A clustered index defines the order in which data is physically stored in a table. Table data can be sorted in only way, therefore, there can be only one clustered index per table. In SQL Server, the primary key constraint automatically creates a clustered index on that particular column.
Non-Clustered Indexes
A non-clustered index doesn’t sort the physical data inside the table. In fact, a non-clustered index is stored at one place and table data is stored in another place. This is similar to a textbook where the book content is located in one place and the index is located in another. This allows for more than one non-clustered index per table.
Please use the link to read complete info
Upvotes: 0
Reputation: 1
The difference of cluster index and non cluster index is:
Upvotes: 0
Reputation: 1165
Clustered Index
Non Clustered Index
Both types of index will improve performance when select data with fields that use the index but will slow down update and insert operations.
The difference is that, Clustered index is unique for any given table and we can have only one clustered index on a table. The leaf level of a clustered index is the actual data and the data is resorted in case of clustered index. Whereas in non-clustered index the leaf level is actually a pointer to the data in rows so we can have as many non-clustered indexes as we can on the database.
Upvotes: 0
Reputation: 26164
Cluster Index
1 A cluster index is a form of tables which consist of column and rows.
2 Cluster index exists on the physical level
3 It sorts the data at physical level
4 It works for the complete table
5 There is a whole table in form of sorted data
6 A table can contain only one cluster index
Non Cluster Index
1 A non cluster index is in the form of a report about the tables.
2 They are not created on the physical level but at the logical level
3 It does not sort the data at physical level
4 A table has 255 non clustered indexes
5 A table has many non clustered indexes.
6 It work on the order of data
Upvotes: 4
Reputation: 115440
A link describing the two.
http://www.mssqlcity.com/FAQ/General/clustered_vs_nonclustered_indexes.htm
http://www.sql-server-performance.com/articles/per/index_data_structures_p1.aspx
The difference is in the physical order of the records in the table relative to the index. A clustered index is physically ordered that way in the table.
Upvotes: 5