Solved

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

Posted on 2013-11-12
10
412 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 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

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…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

696 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