Question

I have a brown-field SQL Server 2005 database that uses standard, unsorted GUIDs as the majority of the primary keys values and also in clustered indexes (which is bad for performance).

How should I go about changing these to sequential GUIDs? One of the challenges would be to replace all of the foreign key values as I change each the primary key.

Do you know of any tools or scripts to perform this type of conversion?

Was it helpful?

Solution

remember that you can only use the newsequentialid() function as a default

so create a new table with 2 columns. Insert the key from you original table into this one (leave the other column out it will fill itself)

join back to the original table and update the PK with the newsequantialid, if you have cascade update the FKs should update by themselves

OTHER TIPS

How do you know it's bad for performance?

The advantage of GUIDs is that you don't have to worry about multiple processes creating records at the same time. It can simplify your code considerably, depending on the program.

SequentialGuids are best for performance when the Guid is the PK. This is the reason behind their existence.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top