Solved

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

Posted on 2013-11-12
10
396 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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 13

Expert Comment

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

Assisted Solution

by:Kdo
Kdo earned 125 total points
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 69

Accepted Solution

by:
ScottPletcher earned 275 total points
Comment Utility
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:Kdo
Kdo earned 125 total points
Comment Utility
>> 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:ScottPletcher
ScottPletcher earned 275 total points
Comment Utility
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:Kdo
Kdo earned 125 total points
Comment Utility
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
Comment Utility
Thanks all.  Points awarded based on perspective that I counldn't find with a standard Google search.  -Jim
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now