?
Solved

Uniqueidentifier vs. int identity(1,1):   Discuss.

Posted on 2013-11-12
10
Medium Priority
?
416 Views
Last Modified: 2013-11-13
So I'm being thrown at a Microsoft Dynamics CRM application, and I see that all the PK / FK's are uniqueidentifier, and not the int identity(1,1) I've seen on almost every other application I've worked with.

Question:  What is the advantage of uniqueidentifier, as opposed to int identity(1,1) ?

Thanks in advance.
Jim
0
Comment
Question by:Jim Horn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 13

Expert Comment

by:Ashok
ID: 39642250
One advantage a GUID has is that it tends to be unique even across databases, but it's a performance and space hit in most applications.

int identity(1,1) uses less space and sequential so it is faster.
0
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 300 total points
ID: 39642293
Only advantage occurs when you insert data from different servers / databases; as the uniqueidentifier is unique, there wont be any issues while inserting the data; other than this, it makes the database larger.  (16bytes  vs 4 bytes , that means per row 12 bytes extra for unique identifier  )
0
 
LVL 13

Assisted Solution

by:Ashok
Ashok earned 100 total points
ID: 39642299
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 13

Expert Comment

by:Ashok
ID: 39642326
Identity does an auto update whereas uniqueidentifier is data specific.
0
 
LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 500 total points
ID: 39642331
Another drawback to unique vs. identity is performance.  

The most efficient join key is an integer.  The least efficient is a string.  On large tables, the joins will be noticeably slower on a unique identifier than on an integer join.
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 1100 total points
ID: 39642430
The use of all GUIDs and/or IDENTITYs is a lazy dodge to proper table designs.

A GUID is worse, of course, because of its randomness and extreme length.

But, contrary to general assumptions, often a natural key of the proper type will perform vastly better on joins than a meaningless identity.  Parent/child joins can be especially faster when clustering the child rows first on the parent's key.
0
 
LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 500 total points
ID: 39642466
>> The use of all GUIDs and/or IDENTITYs is a lazy dodge to proper table designs.

That's not really true.  The data can be organized and stored to be most advantageous.  An identity just enumerates the data and becomes the fastest join key.  Dimension tables in a star schema are a good example.


Kent
0
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 1100 total points
ID: 39642751
We're talking OLTP not OLAP.

I think it's lazy to assume that the proper clustering key for ALL data at ALL times is a meaningless, auto-generated number.  I'm glad the Contacts on my phone are ordered by Name and not by the order I added them.
0
 
LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 500 total points
ID: 39642843
If your phone book is joined to other demographics, the join will be faster if there's an identity column in the phone book and the join is performed on the scalar integer identity key than on the composite string key that is last, first.
0
 
LVL 66

Author Closing Comment

by:Jim Horn
ID: 39645060
Thanks all.  Points awarded based on perspective that I counldn't find with a standard Google search.  -Jim
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question