Example 1
Generate a single UUID
Each engine generates a globally unique identifier on every call. MySQL and MariaDB use a time-based algorithm (version 1) that encodes the MAC address and a timestamp, which means consecutive UUIDs are somewhat ordered. SQL Server's NEWID() and PostgreSQL's gen_random_uuid() use a random algorithm (version 4) that gives no ordering guarantees. To use a UUID as a column default, place the function call in the column definition: id CHAR(36) DEFAULT (UUID()) in MySQL 8.0.13+, id UNIQUEIDENTIFIER DEFAULT NEWID() in SQL Server, or id UUID DEFAULT gen_random_uuid() in PostgreSQL. For high-insert-rate workloads on PostgreSQL, consider UUIDv7 (available via extensions) which is time-ordered and causes fewer B-tree index page splits.
The value differs on every call. The format is always 8-4-4-4-12 lowercase hex digits separated by hyphens.