Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-11-12
10
Medium Priority
?
419 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 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
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 70

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 70

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

971 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