Why is it good to use a UUID as a PK?

Why is it good to use a UUID as a PK?

Reasons UUIDs are Good. There are several reasons using a UUID as a PK would be great compared to auto-incrementing integers: At scale, when you have multiple databases containing a segment (shard) of your data, for example a set of customers, using a UUID means that one ID is unique across all databases, not just the one you’re in now.

When to use UUID or INT for primary key?

By using UUID, you can generate the primary key value of the parent table up front and insert rows into both parent and child tables at the same time within a transaction. Besides the advantages, UUID values also come with some disadvantages:

Is it safe to use UUID value in url?

UUID values do not expose the information about your data so they are safer to use in a URL. For example, if a customer with id 10 accesses his account via http://www.example.com/customers/10/ URL, it is easy to guess that there is a customer 11, 12, etc., and this could be a target for an attack.

When to use UUID to move data across databases?

At scale, when you have multiple databases containing a segment (shard) of your data, for example a set of customers, using a UUID means that one ID is unique across all databases, not just the one you’re in now. This makes moving data across databases safe.

What’s the difference between a GUID and a PK?

GUIDs joins can be copied without any worry. PK = GUID. GUIDs are indexed similar to strings, so high row tables (over 50 million records) may need table partitioning or other performance techniques. SQL Server is getting extremely efficient, so performance concerns are less and less applicable. PK Guid is NON-Clustered index.

Why are UUIDs not used as primary keys?

For each of these columns in a set of table with billions of accounts, the extra size of foreign keys adds up fast. Another problem is fragmentation — because UUIDs are random, they have no natural ordering so cannot be used for clustering.