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
Solved

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

Posted on 2013-11-12
10
410 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
  • 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 75 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 25 total points
ID: 39642299
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 13

Expert Comment

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

Assisted Solution

by:Kent Olsen
Kent Olsen earned 125 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 275 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 45

Assisted Solution

by:Kent Olsen
Kent Olsen earned 125 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 275 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 45

Assisted Solution

by:Kent Olsen
Kent Olsen earned 125 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 65

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

791 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