views:

204

answers:

4

When or why will one need to use Globally Unique Identifiers instead of the traditional Idenity column? Please help me understand

+3  A: 

One reason is replication and scalability: When multiple, uncoordinated writers exist, they -- by definition -- have no channel to communicate for creating unique ints for the primary key. GUIDs don't need communication to be unique.

David Schmitt
A: 

GUIDs are often used in situations where there's a need for replication, in order to avoid the complication of conflicting primary keys from different locations.

If I'm working on a system that will not use replication, I will more often than not avoid the complication and overhead of using GUIDs.

Galwegian
+2  A: 

In addition to the replication elements mentioned by other answers...

When you need to create unique values but do not have access to the master database or do not want to write out the data first. This is particularly true of systems that synchronise. For example, a sales force tool that allows unconnected salespeople to create data and write it to the database at a later time.

In the case of identities, you must write a row into the database before you can determine what the unique key will be. With GUIDs, you can generate the GUID in code externally to the database, without needing the database to be available at all.

BlackWasp
A: 

There are (at least) two situations where Guid's are really useful.

  1. With replication or any kind of multi-site setup where databases will be merged Guid's make it much easier. Int keys can be used as well in this situations but Guid's are easier and will present less problems.
  2. Generating keys client side before inserting without the need to round trip to the DB can be very useful.
Craig