SQL Server GUIDS (Globally Unique Identifiers)
-
Upload
aaron-buma -
Category
Software
-
view
844 -
download
0
Transcript of SQL Server GUIDS (Globally Unique Identifiers)
Unique Identifiers - GUIDs
Presentation by Aaron BumaDevelopment DBA
Session Overview
• Overview• Generation• Comparison and Non-Comparison Operations• Advantages and Disadvantages
GUID Overview
• GUID – Global Unique Identifier• Unique – 2^128 possible values• A unique 16-byte number• Can be auto-generated on a column– IDENTITY and TIMESTAMP (2008-)/ROWVERSION(2008+)
GUID Generation
• On the fly:
• From a String (too long of string will be trimmed):
• Auto-Generate:
GUIDS
GUID Generation
• NEWID:– A random 16 byte identifier
• NEWSEQUENTIALID:– Can only be a DEFAULT when record is created
GUIDS
Comparison (and non) OperationsCan Use Can’t Use
=, !=, <> +, -, *, /
<, <=, >, >=
LIKE
BETWEEN
IS NULL and IS NOT NULL
GUIDs and ORDER BY• When using “ORDER BY” on a GUID column, the data
is sorted on the last section of the GUID
DEMOS
Advantages of GUIDs
• Identifying data from multiple sources– An advantage over IDENTITY
• Can be generated offline
Disadvantages of GUIDs
• Data Size: 4x larger than INT– Slower and Larger Indexes– Page Splits on Indexes (fragmentation)
• Slowest JOIN performance• Slowest INSERT/UPDATE performance• Slowest SORT performance
Disadvantages of GUIDs
• Adding/Removing GUIDs will cause fragmentation on indexes if GUIDs are used for:– Primary Keys • GUIDs have least performance on JOINS, so not only is
JOINING on a GUID slow, but joining to a fragmented index is even slower
– Clustering
Advantage vs Disadvantages
<
Review• Overview• Generation• Comparison and Non-Comparison Operations• Advantages and Disadvantages
Presentation Recording, Slides and Scripts– Available at: http://www.aaronbuma.com/2015/10/guids/