![Page 1: SQL Server GUIDS (Globally Unique Identifiers)](https://reader036.vdocument.in/reader036/viewer/2022081520/5882276e1a28ab52368b5419/html5/thumbnails/1.jpg)
Unique Identifiers - GUIDs
Presentation by Aaron BumaDevelopment DBA
![Page 2: SQL Server GUIDS (Globally Unique Identifiers)](https://reader036.vdocument.in/reader036/viewer/2022081520/5882276e1a28ab52368b5419/html5/thumbnails/2.jpg)
Session Overview
• Overview• Generation• Comparison and Non-Comparison Operations• Advantages and Disadvantages
![Page 3: SQL Server GUIDS (Globally Unique Identifiers)](https://reader036.vdocument.in/reader036/viewer/2022081520/5882276e1a28ab52368b5419/html5/thumbnails/3.jpg)
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+)
![Page 4: SQL Server GUIDS (Globally Unique Identifiers)](https://reader036.vdocument.in/reader036/viewer/2022081520/5882276e1a28ab52368b5419/html5/thumbnails/4.jpg)
GUID Generation
• On the fly:
• From a String (too long of string will be trimmed):
• Auto-Generate:
GUIDS
![Page 5: SQL Server GUIDS (Globally Unique Identifiers)](https://reader036.vdocument.in/reader036/viewer/2022081520/5882276e1a28ab52368b5419/html5/thumbnails/5.jpg)
GUID Generation
• NEWID:– A random 16 byte identifier
• NEWSEQUENTIALID:– Can only be a DEFAULT when record is created
GUIDS
![Page 6: SQL Server GUIDS (Globally Unique Identifiers)](https://reader036.vdocument.in/reader036/viewer/2022081520/5882276e1a28ab52368b5419/html5/thumbnails/6.jpg)
Comparison (and non) OperationsCan Use Can’t Use
=, !=, <> +, -, *, /
<, <=, >, >=
LIKE
BETWEEN
IS NULL and IS NOT NULL
![Page 7: SQL Server GUIDS (Globally Unique Identifiers)](https://reader036.vdocument.in/reader036/viewer/2022081520/5882276e1a28ab52368b5419/html5/thumbnails/7.jpg)
GUIDs and ORDER BY• When using “ORDER BY” on a GUID column, the data
is sorted on the last section of the GUID
![Page 8: SQL Server GUIDS (Globally Unique Identifiers)](https://reader036.vdocument.in/reader036/viewer/2022081520/5882276e1a28ab52368b5419/html5/thumbnails/8.jpg)
DEMOS
![Page 9: SQL Server GUIDS (Globally Unique Identifiers)](https://reader036.vdocument.in/reader036/viewer/2022081520/5882276e1a28ab52368b5419/html5/thumbnails/9.jpg)
Advantages of GUIDs
• Identifying data from multiple sources– An advantage over IDENTITY
• Can be generated offline
![Page 10: SQL Server GUIDS (Globally Unique Identifiers)](https://reader036.vdocument.in/reader036/viewer/2022081520/5882276e1a28ab52368b5419/html5/thumbnails/10.jpg)
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
![Page 11: SQL Server GUIDS (Globally Unique Identifiers)](https://reader036.vdocument.in/reader036/viewer/2022081520/5882276e1a28ab52368b5419/html5/thumbnails/11.jpg)
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
![Page 12: SQL Server GUIDS (Globally Unique Identifiers)](https://reader036.vdocument.in/reader036/viewer/2022081520/5882276e1a28ab52368b5419/html5/thumbnails/12.jpg)
Advantage vs Disadvantages
<
![Page 13: SQL Server GUIDS (Globally Unique Identifiers)](https://reader036.vdocument.in/reader036/viewer/2022081520/5882276e1a28ab52368b5419/html5/thumbnails/13.jpg)
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/