Hello.
Are you using asp.net membership by any chance?
Anyway, it is possible to have a guid as a primary key but this is not recommended due to the random nature of the guid produced (as others have stated). However, SQL Server 2005 has a new default datatype called NewSequentialID. This beauty will create a valid uniqueidentifer but each newly created value will ALWAYS be greater than the previous by exactly 1! Therefore, you have a column that is both using a unique value and is incrementing by 1. Indexes obviously find this much more appealing.
The peformance is not equal to a surrogate int identity column but it is very very close and much much faster than using the standard uniqueidentifer guid.
SQL Server will only let you use this as a default value on a field i.e. you cannot use it in an insert sproc directly, you have to set the default value of the field to newsequentialid() and let sql server do the rest. The only downside as I see it is the fact that the unique identifer becomes predictable as it only increments by one - so it could be a security risk if it was ever exposed to users. To be honest though, and I am only speaking from asp.net perspective, this should be very easy to ensure never happens.
|
Reads |
Writes |
Leaf Pages |
Avg Page Used |
Avg Fragmentation |
Record Count |
| IDENTITY(,) |
0 |
1,683 |
1,667 |
98.9% |
0.7% |
50,000 |
| NEWID() |
0 |
5,386 |
2,486 |
69.3% |
99.2% |
50,000 |
| NEWSEQUENTIALID() |
0 |
1,746 |
1,725 |
99.9% |
1.0% |
50,000 |
For more info on this:
http://www.fotia.co.uk/fotia/DY.19.NewSequentialId.aspx
Altering asp.net membership:
http://www.ericswann.org/blog/archive/2008/03/15/asp.net-sql-server-2005-membership-provider-and-newsequentialid.aspx
Hope this helps.