Thursday, January 8, 2009

Advantages of Using Globally Unique Identifier (GUID) as a Primary Key.

Advantages of Using Globally Unique Identifier (GUID) as a Primary Key Advantages:
 
■ If you use an auto-number Id column and if many people are creating new DataRow objects, it will be difficult for you to merge data later because there may be many duplicate keys.

■ The Guid data type is a “surrogate” key, meaning that its only purpose is to define uniqueness of the row and aid in connecting multiple tables together via relationships. This means that there is no reason for a user to see and change this value, which simplifies maintenance of the DataSet. If you allow the user to change the primary key on a row, you have to propogate the change down to all of the related tables. For example, changing the CompanyId value requires the update of the Company Id value in the Employee table.

■ The use of the Guid can simplify the joining of tables, which is better than the scenarios where you use compound keys that are based on the actual data. Compound keys typically result in smaller data footprints because the key is based on actual data, whereas joining tables is usually more difficult because compound joins are required. Remember that if you are using compound keys that are based on the actual data, you inevitably need to deal with recursive updates.

No comments: