We are using GUID as primary key (we know it's not good option, but can not change now). So as all know our indexes get fragmented very quickly. Another good option to replace the GUID by Sequential ID. To do this, Code change is like:
Old Code :
ObjectName.Id = Guid.NewGuid();
New Code :
ObjectName.Id = Sequential.NewGuid();
Here Sequential is our static class, which creates the Sequential GUID using "rpcrt4.dll". But our tests shows that this also does not work well with the indexes, and they get fragmented.
Another interesting finding is that, if we save this sequential GUID as "String" in the database then our indexes are not getting fragmented.
Now I have following doubts/queries:
Why Server is behaving differently when we are saving the same string as "String" and "GUID"? As per my understanding till now, internally it saves everything as String.
Is there any way to configure the database to tell that, consider our GUID as string and treat them equally?
Here are some details of environment:
- Database: SQLExpress
- Coding language: C#
- Can not rely on Server to generate the key, we have to set the key from code itself.
Even if not exact solutions, pointers to the solution are also welcome.