Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 UniqueIdentifier as Clustered Index

Author  Topic 

gregoryagu
Yak Posting Veteran

80 Posts

Posted - 2008-07-14 : 14:36:48
I have a table which uses as its primary key a uniqueidentifier (Guid). This column was indexed, but the table was a heap - ie no clustered index.

So I turned the index into a clustered index and queries now run much faster.

However, a co-worker says that this is not a good idea - that a GUID should not be a clustered index as it will cause page fragmentation over time as we are not using a seqential GUID.

Is he correct? Is this not a good idea? I have done many tests and indeed having a clustered index improves the speed dramatically.

The table is not an a high use table, many more reads than writes, a typical customer name address etc. In other words, there is not a lot of updates going on in the table.

So, is there a downside to using the Guid as the clustered index?

Greg

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-14 : 14:43:40
Please search the forums for this discussion as it has been covered already at length.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-14 : 14:44:33
I've also heard that its not recommended to use GUID as clustered indexes. We are always told to use identity columns as clustered indexes.
Go to Top of Page

gregoryagu
Yak Posting Veteran

80 Posts

Posted - 2008-07-14 : 15:08:52
The following quote is all that I could find on searching SQLTeam on "UniqueIdentifier Clustered Index" Is there a better search phrase?

"GUIDs are not good candidates for clustered indexes, especially on tables that have a lot of insert activity. But they are perfectly fine for non-clustered indexes."

I agree that an indentity column would be better, but in this case, the database is already in production and I can't change that aspect of it. Also there is not a lot of insert activity on the table. The guid is used in almost all of the joins, so there I don't see a way around using it as a clustered index. The table in question is only two fields, the guid and an SQLVarient.

Greg
Go to Top of Page
   

- Advertisement -