Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GUID vs INT IDENTITY [duplicate]

Possible Duplicate:
How do you like your primary keys?

I'm aware of the benefits of using a GUID, as well as the benefits of using and INT as a PK in a database. Considering that a GUID is in essence a 128 bit INT and a normal INT is 32 bit, the INT is a space saver (though this point is generally moot in most modern systems).

In the end, in what circumstances would you see yourself using an INT as a PK versus a GUID?

like image 611
CodeMonkey1313 Avatar asked May 06 '09 12:05

CodeMonkey1313


People also ask

Should I use int or GUID as primary key?

An INT is certainly much easier to read when debugging, and much smaller. I would, however, use a GUID or similar as a license key for a product. You know it's going to be unique, and you know that it's not going to be sequential.

Is it good to use GUID as primary key?

GUIDs may seem to be a natural choice for your primary key - and if you really must, you could probably argue to use it for the PRIMARY KEY of the table. What I'd strongly recommend not to do is use the GUID column as the clustering key, which SQL Server does by default, unless you specifically tell it not to.

When should I use GUID?

The guid can be used as needed to globally uniquely identify the row and id can be used for queries, sorting and human identification of the row. The id identifies the row in this table. The GUID (at least in theory) identifies this row anywhere in the known universe.

Is GUID an integer?

A GUID is a 128-bit integer (16 bytes) value. That means that there are more than 300, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000 different values.


1 Answers

Kimberley Tripp (SQLSkills.com) has an article on using GUID's as primary keys. She advices against it because of the unnecessary overhead.

like image 127
Ronald Wildenberg Avatar answered Oct 11 '22 19:10

Ronald Wildenberg