|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Tuesday, March 16, 2010 8:57 PM
Points: 88,
Visits: 410
|
|
| why can we have only one clustered index per table.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: 2 days ago @ 6:27 PM
Points: 817,
Visits: 12,627
|
|
because a clustered index physically stores the records in that order, therefore as you can only store the data in one order you can only have one clustered index.
Non clustered indexes store pointers in a seperate file location within the data file.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, March 16, 2010 7:42 AM
Points: 1,034,
Visits: 381
|
|
You should read up on exactly what a clustered index is rather than a regular non-clustered index and the difference will make it obvious.
Essentially a clustered index defines the physical ordering of the data in the table. Obviously the data in the table can only be ordered once - all other (non-clustered) indices store a subset of the columns in a certain order as well as storing the contents of each row as far as the clustered index is concerned. This allows the non-clustered index to do a "bookmark lookup" if need be to access the table/clustered index to retrieve other column values.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Thursday, February 26, 2009 3:02 PM
Points: 515,
Visits: 655
|
|
sandhyarao49,
SQL Server 2005 Books Online (September 2007) CREATE INDEX (Transact-SQL) http://msdn2.microsoft.com/en-us/library/ms188783.aspx
Clustered Index The bottom, or leaf, level of the clustered index contains the actual data rows of the table. A table or view is allowed one clustered index at a time. For more information, see Clustered Index Structures.
For further reading and/or reference ...
SQL Server 2005 Books Online (September 2007) Clustered Index Structures http://msdn2.microsoft.com/en-us/library/ms177443.aspx
SQL Server 2005 Books Online (September 2007) Nonclustered Index Structures http://msdn2.microsoft.com/en-us/library/ms177484.aspx
Happy T-SQLing,
"Key" MCITP: DBA, MCSE, MCTS: SQL 2005, OCP
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Tuesday, October 27, 2009 4:17 PM
Points: 85,
Visits: 202
|
|
Why would you want to ?
The primary clustering is designed to limit the number of index pages that need to change each time a row updates onto a new data page. In this scenario only the primary clustered index would change.
Adding a second clustering index would force the system to update both of the 'clustering indexes' to point to the correct data page.
If you are not trying to limit the amount of pages touched for Update you could investigate non-clustered indexes on a table without a clustering index (or a heap). As in this case the non-clustered indexes refer to the data pages and not the primary clustering index values. (and in this scenario both would be maintained on each row update onto a new page)
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 7:29 AM
Points: 2,019,
Visits: 1,653
|
|
A clustered index physically stores the data in the sequence given in the index definition. The way this is implemented in SQL Server means you can only have 1 clustered index per table.
This is true in most other DBMSs, but not all of them. DB2 has supported multiple clustered indexes for some years (for *nix and Windows) and now also on the mainframe. You can define a large number (256?) cluster indexes on the same table. The data is stored only once, but is physically ordered by the sequence defined for each index.
Author: SQL Server FineBuild 1-click install and best practice configuration of SQL Server 2005, 2008, and 2008 R2. 24 February 2010: now over 9,000 downloads. Disclaimer: All information provided is a personal opinion that may not match reality. Concept: "Pizza Apartheid" - the discrimination that separates those who earn enough in one day to buy a pizza if they want one, from those who can not.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, January 22, 2010 9:08 AM
Points: 167,
Visits: 263
|
|
EdVassie (4/15/2008) A clustered index physically stores the data in the sequence given in the index definition. The way this is implemented in SQL Server means you can only have 1 clustered index per table.
This is true in most other DBMSs, but not all of them. DB2 has supported multiple clustered indexes for some years (for *nix and Windows) and now also on the mainframe. You can define a large number (256?) cluster indexes on the same table. The data is stored only once, but is physically ordered by the sequence defined for each index. It is possible in SQL Server, you just need to do it by way of indexed views, which results in a second copy of the table. Given the nature of clustered indices, I really don't see any way to have multiple clustered indices without storing multiple copies of the data, as it's not clustered unless it's physically stored in that order.
Puto me cogitare, ergo puto me esse. I think that I think, therefore I think that I am.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 7:29 AM
Points: 2,019,
Visits: 1,653
|
|
I really don't see any way to have multiple clustered indices without storing multiple copies of the data, as it's not clustered unless it's physically stored in that order.
In DB2, the data is stored once, and physically clustered in multiple dimensions. All it needs is a bit of lateral thinking. Consider the following...
You have a collection of objects you want to cluster by shape, by size, and by colour.
Store all the small round red things in one database extent "a". Store all the small square blue things in extent "b". Store all the large triangular blue things in extent "c".
Create a new type of index that only knows about extents. Call it a Multiple Dimension Clustering type of index.
Define an index for size. This has 3 entries: large, "c"; small, "a"; small, "b". Define an index for shape. This has 3 entries: round,"a"; square,"b"; triangular,"c" Define an index for colour. This has 3 entries: blue, "b"; blue, "c"; red,"a"
You want all the blue things, the database gets you extents "b" and "c". You want all the small things, the database gets you extents "a" and "b" You want the blue square things, the database gets you extent "b" In each extent that is returned, ALL the rows match your WHERE clause.
So storing a data item once only and physically clustering it in multiple dimensions can be done. You just dedicate a whole extent to store the intersection of all your clustering indexes.
In DB2, you can set the extent size for each filegroup (called tablespace in DB2) so you can tune this value to minimise unused space in the extent. The DB2 MDC index pointers are the same size as normal RID pointers, but only the extent level information is populated, allowing normal and MDC indexes to be used in the same query with standard index AND and OR logic. This is a cool feature in DB2 but with weaknesses as well as strengths. It would be nice if SQL Server also had this technology - I am sure IBM would licence another one of its database patents to Microsoft for a suitable fee.
Author: SQL Server FineBuild 1-click install and best practice configuration of SQL Server 2005, 2008, and 2008 R2. 24 February 2010: now over 9,000 downloads. Disclaimer: All information provided is a personal opinion that may not match reality. Concept: "Pizza Apartheid" - the discrimination that separates those who earn enough in one day to buy a pizza if they want one, from those who can not.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, January 22, 2010 9:08 AM
Points: 167,
Visits: 263
|
|
This sounds like unclustered indexes on a grouped heap. Granted, grouping the heap is an interesting idea, but I wouldn't call it multiple clustered indices.
Puto me cogitare, ergo puto me esse. I think that I think, therefore I think that I am.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 7:29 AM
Points: 2,019,
Visits: 1,653
|
|
The description I gave about MDC was very simplified. If you want more details then you have to search the DB2 documentation.
Believe me, MDC does what it says on the tin.
Author: SQL Server FineBuild 1-click install and best practice configuration of SQL Server 2005, 2008, and 2008 R2. 24 February 2010: now over 9,000 downloads. Disclaimer: All information provided is a personal opinion that may not match reality. Concept: "Pizza Apartheid" - the discrimination that separates those who earn enough in one day to buy a pizza if they want one, from those who can not.
|
|
|
|