When you need more than one Unique ID {NEWID(), NEWSEQUENTIALID()}

Reading up on SQL Server Central article (Randomizing Result Sets with NEWID) on how to implement real Random sets I considered writing about the importance of GUID‘s and their most common implementation.

We typically use integer numbers as primary keys in most of tables but when non persistent data (or session data) is manipulated using a GUID becomes a necessity. We do know there is a slight chance that a GUID could be repeated but it is so low the benefits of using it make this depreciable. commonly we use NEWID() as the default value on a uniqueidentifier column but the benefits in querying and overall readability make NEWSEQUENTIALID() a better suit in this case.

As an example imagine a web application that collects user data but does not store it in your tables until user creates a login or account. We can handle most of this information on a separate table and XML drafts and link the two with these unique GUIDs.

So go ahead and give them a try it will sure come in handy some day.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: