Are There That Many GUIDs?

This editorial was originally published on Oct 12, 2010. It is being re-run as Steve is away on vacation.

Do a lot of people actually use GUIDs as Primary Keys? I haven't used them much, and I would have thought that more people chose identity keys. It seems that most of the demos and examples I see from bloggers and speakers are constantly using identities.

However an informal survey from Peter Bromberg showed that four times as many people actually had GUIDs as their primary keys. The blog actually says that GUIDs are not a good choice, but I'm not sure I agree with that. You can use sequential GUIDs, and you can avoid making them the clustered key, so I think they can work as well as anything.

There's nothing inherently wrong with GUIDs, and they should be unique across all of your rows. There have been some reported cases of duplicates, but for most practical purposes, especially in database work, you ought to be able to count on a GUID as unique. They even have the nice capability of being generated by clients, removing the need for an extra round trip when a client needs to insert multiple rows.

I typically don't use them because they're long, hard to remember and type, and hard to view on the screen. I can't easily compare rows in multiple tables, and it's easier for me to work with integers. I don't recommend them, but if you are going to use them, be sure you understand the pros and cons, and use them appropriately.