Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is better to use an UUID to store unique id values?

Tags:

uuid

Why is better to use an UUID to store unique id values? What are the benefits?

like image 985
Simone Avatar asked Nov 04 '10 14:11

Simone


People also ask

What is the advantage of UUID?

The main advantage of using UUIDs is that you can create a UUID and use it to identify something, such as a row in a database, with near certainty that the identifier will not exist in another row in your system or anyone else's.

When should we use UUID?

A UUID – that's short for Universally Unique IDentifier, by the way – is a 36-character alphanumeric string that can be used to identify information (such as a table row).

Why you should use UUID as primary key?

UUIDs as primary key aren't a slam drunk, but do have some advantages: The fact that they're random means that they don't rely on a single sequence to be generated. Multiple entities can generate IDs independently, but still store them to a shared data store without clobbering each other.

What is the use of UUID in database?

A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. You can create a UUID and use it to uniquely identify something.


1 Answers

Two reasons.

A regular ID is only unique within your table inside of your system. If you ever need to integrate systems there is going to be conflict. UUID is guaranteed to be unique across systems.

A second reason is often you don't want people to know how many records you have in your system. If you have an id with 1,2,3,4,5,6,ect someone can easily figure out how big or small your system is.

like image 104
zgirod Avatar answered Oct 06 '22 00:10

zgirod