RSS Feed

GUID vs INT

GUID vs INT

Most of the time we deal with a situation to insert records in a table. While inserting we need to have a sequence or just a number which uniquely identifies and separates that record from other records. The most frequently used idea which comes to a developer’s mind for this concern comes out to be either using GUID or the INT. In this, we will be learning about the difference between GUID & INT, with their advantages and disadvantages.

INT

INT is just a data type assigned to column which allows only the numeric values. It stores whole number from -2,147,483,648 through 2,147,483,647.

Advantages of INT:

1. INT number is easy to recall and also increases readability.
2. While testing it is easy to find which record is currently being tested.
3. Memory usage is very less (int takes 4 bytes).
4. Chronicle order of data. It means if there are 2 records and those are in ascending order, we can easily find that the 2nd record was inserted after the 1st one.
5. It also supports functions like SCOPE_IDENTITY(),@@IDENTITY.

Disadvantages of INT:

1. It is very difficult to merge tables with INT values on primary key because the keys can have same values which require remapping.
2. It makes very difficult to work with tables which are distributed.
3. When there are more numbers of actions like insert, delete etc. performed then the counter for the key can be reset, which creates ambiguity with the new and the old records with same INT value.
4. Any key which is INT is referred as LUID i.e. Local Unique Identifier, which means that it can be used locally in a table.

Example of INT: 1, 2, 3…… 200 & so on.

GUID

GUID stands for Global Unique Identifier. It gives large range of unique values to the key column than the integer (INT) column. It remains unique across the server. It contains alphanumeric (i.e. string as well as numbers) value which will be different from one another.

Advantages of GUID:

1. With GUID, It becomes very easy to merge tables.
2. In GUID case, it makes easy to work with tables which are distributed.
3. The key inserted from GUID will be identified uniquely in the entire server.
4. It will not create problems when performing large no. of operations.

Disadvantages of GUID:

1. It is bit hard to remember and use in testing.
2. With this, there is no chronology assumption.
3. It takes much bigger space as compare to INT. It takes up to 16 bytes which is 4 times the size of an INT.

Example of GUID: 268AF621-76D7-4C78-9441-144FD139821A, 981B3303-ACA2-49C7-9A96-FB670785B269 etc.