SQL Server 2005 – Add a uniqueidentifier column in exisiting table and populate column with unique GUIDs

Many DBAs prefer to have “uniqueidentifier” as a table identifier in their data model design over “identity” column. That way DBAs can easily import-export SQL Server tables and data from one database to other database without worrying about uniqueness of the data.

Sometimes you want to import data from external sources during ETL (extract, transform, and load) process and needs to create GUID column on fly and populate data with unique GUIDs. Here is how you do that.

ALTER TABLE Employee
ADD EmployeeID uniqueidentifier null
CONSTRAINT Guid_Default
DEFAULT NEWSEQUENTIALID() WITH VALUES

Advertisements
This entry was posted in SQL Server. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s