Welcome to ciysys blog

Primary key in uniqueidentifier

Published on: 20th Jun 2012

Updated on: 15th May 2021

Overview

We used to define the primary key in integer type. Usually, an auto-increment primary key field. This was convenient until one day that we were working on a web project. We quickly realized that using integer type for primary key is going to cause some issues.

Some issues causes by integer as primary key

How to solve this puzzle

After trial and error with integer primary key and nvarchar (i.e., add an "outlet code" field to make the composite key), we found an easier way to solve the above problem. We decided to use UNIQUEIDENTIFIER data type (or GUID in .Net framework).

It's time to make a judgement call

In fact, using UNIQUEIDENTIFIER data type comes with some costs.

Reviews on 15th May 2021

As of 15th May 2021, we never face any issue with this implementation.

Jump to #MSSQL blog

Author

Lau Hon Wan - the developer and business owner.