January 2, 2015 at 3:11 am
1). What is the difference between Clustered Index and Non-Clustered Index?
2). How these both indexes are related?
3). A table with Clustered Index and another table with Non-Clustered Index, which one will perform better and why?
4). How these two indexes affect tables (in DML)?
January 2, 2015 at 4:47 am
lokesh.shukla-634965 (1/2/2015)
1). What is the difference between Clustered Index and Non-Clustered Index?2). How these both indexes are related?
3). A table with Clustered Index and another table with Non-Clustered Index, which one will perform better and why?
4). How these two indexes affect tables (in DML)?
1.
Clustered Index:
When a Clustered Index is created on a table, the table data is physically sorted as per the clustered index key. That is the reason you can have only one Clustered Index on a table.
Non-Clustered Index:
The index pages of Non-Clustered index contain two things i.e. index key & a pointer to the particular data row in the table. This pointer might either be a Row Id (File Id + Page Id + Row Slot)if the table is a heap OR the clustered index key value if a clustered index has already been created on table. You can have 999 non-Clustered indexes on a table (SQL Server 2008 & above).
2.
See answer number 1 (Non-Clustered index).
3.
If we are talking about an index created on the same column, Clustered index tends to perform better. However there are various other things that affect how the query\index will perform such as statistics of the table, SARGability & whether or not index is being used by the query. Creating random index is only going to make matter worse.
4.
Indexes do affect the DML operation, however generally the performance gain in read operation is way more high than the penalty incurred in write operations. In case your table is going to receive write activity more frequently than the read activity then the index should be created with much more caution.
Must Read:
http://www.sqlservercentral.com/articles/Indexing/68439/
January 2, 2015 at 4:56 am
By the way your post should be opened under General SQL Server Questions not under "Discuss Content Posted by Steve Jones" ;-).
January 3, 2015 at 1:36 am
Thanks Sujeet, for your nice comments and the link provided.
But, my 2nd question is still not better understood (How clustered index and non-clustered index are related?).
Can you elaborate it more?
January 3, 2015 at 2:58 am
lokesh.shukla-634965 (1/3/2015)
Thanks Sujeet, for your nice comments and the link provided.But, my 2nd question is still not better understood (How clustered index and non-clustered index are related?).
Can you elaborate it more?
Did you have a look at the series of articles I recommended?
January 3, 2015 at 9:19 am
These look like interview, homework, or test questions. I strongly recommend that you open "Books Online" (the help system for SQL Server) and start reading all you can about indexes because just knowing the answers to the questions you posted won't help you in your job. Only a deep understanding will do that. Use these questions as the first part of a study guide rather than an end to the means.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 4, 2015 at 9:58 am
Divine Flame (1/2/2015)
When a Clustered Index is created on a table, the table data is physically sorted as per the clustered index key.
Logically. Not physically. Same as nonclustered indexes
If the clustered index enforced the physical sort order, then a clustered index would always have 0% logical fragmentation, since fragmentation is a measure of how the logical and physical orders differ.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 5, 2015 at 3:00 am
GilaMonster (1/4/2015)
Divine Flame (1/2/2015)
When a Clustered Index is created on a table, the table data is physically sorted as per the clustered index key.Logically. Not physically. Same as nonclustered indexes
If the clustered index enforced the physical sort order, then a clustered index would always have 0% logical fragmentation, since fragmentation is a measure of how the logical and physical orders differ.
Thanks Gail & Lutz for correcting me there.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply