Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does performance of guids compare to strings in sql

For primary keys on a large SQL Server 2008 data table, I have the choice of using guids or a string of about the same size.

Performance-wise, how does a guid (16 bytes) compare to a string of about 16 chars, when doing joins, selects, etc. Is SQL better at handling guids because internally they are represented as a number?

like image 972
Carvellis Avatar asked Sep 10 '25 03:09

Carvellis


1 Answers

The short answer to your question is, ideally, to use neither.

If you can use an int/bigint key (as I suggested in my answer to your related question), you should.

Unless you need the functionality to non-destructively merge copies of this dataset stored on more than one SQL Server instance, using a GUID primary key adds a considerable overhead in index maintenance. This article has a reasonable discussion of the issue.

A string PK should have less overhead if the sequence you generate is consistently ordered - i.e. new values are always added at the "end" of the table.

like image 109
Ed Harper Avatar answered Sep 13 '25 08:09

Ed Harper