UUID (universally unique identifier)
A UUID hands out globally unique keys without a round trip to the database: any server, any offline client, no collisions. Only some engines give it a real column type; the rest store a string or a byte array and get along fine.
- Family
- UUIDs & identifiers
- Missing in
- None of the five
- Gotchas
- 5 listed
Engine by engine
Every engine can hold a UUID. The differences are whether it has a native type, how many bytes it costs (16 vs 36), and whether the engine generates one for you.
| Motor | Tipo | Almacenamiento | Notas |
|---|---|---|---|
| SQL Server |
UNIQUEIDENTIFIER
|
16 bytes | NEWID() generates a random version-4 value, NEWSEQUENTIALID() an increasing one. ORDER BY compares the last 6 bytes first, so the sort order differs from the text form. |
| PostgreSQL |
UUID
|
16 bytes | Native type; gen_random_uuid() (version 4) is built in since PostgreSQL 13, and uuidv7() (time-ordered) since PostgreSQL 18. |
| MySQL |
BINARY(16) or CHAR(36)
|
16 or 36 bytes | No native UUID type. UUID() returns a 36-char string; UUID_TO_BIN(..., 1) in 8.0 packs it into BINARY(16) and can swap the timestamp block for better index locality. |
| SQLite |
TEXT
|
36 bytes | No UUID type and no built-in generator (the uuid extension is optional). Store the hyphenated text or a 16-byte BLOB; randomblob(16) gives random bytes but not a valid v4 layout. |
| Oracle |
RAW(16)
|
16 bytes | SYS_GUID() returns a 16-byte RAW that is not an RFC 4122 UUID; recent 23ai releases add UUID(), which returns a random version-4 RAW(16). Formatting as 8-4-4-4-12 is your job. |
Gotchas
Where the engines disagree. These tend to surface as bugs during a migration or a port.
- NEWID() values are random, so as a clustered key they land all over the index and split pages. NEWSEQUENTIALID() fixes that but only works in a DEFAULT constraint, and its sequence can restart lower after a Windows reboot.
- The same UUID is spelled differently per engine: SQL Server prints uppercase (and accepts braces on input), PostgreSQL prints lowercase, Oracle RAW(16) is hex with no dashes, and SQLite holds whatever text you put in. Normalize on write or text joins silently miss.
- MySQL UUID() is version-1 style (time and MAC based), which leaks the host's identity and needs UUID_TO_BIN plus BINARY(16) if you want compact storage.
- SQLite has no built-in UUID generator, so a DEFAULT that generates the id does not port; the application (or a loaded extension) must create it.
- Oracle SYS_GUID() values are not RFC UUIDs and are often nearly sequential, so mixing them with app-generated v4 UUIDs in one RAW(16) column works but leaves two id formats to explain.
Common questions
Does MySQL have a UUID type like PostgreSQL?
No. MySQL stores UUIDs either as CHAR(36) text or, better, packed into BINARY(16) with UUID_TO_BIN(). 8.0's UUID_TO_BIN(..., 1) also reorders blocks so sequential UUIDs index better.
Should I store a UUID as text or bytes?
Bytes: 16 bytes in BINARY(16)/RAW(16)/bytea vs 36 as text. Text wins only when humans read the column or the file format demands it, such as a plain SQLite column.
Why do random UUIDs slow down SQL Server?
They enter the clustered index in random order, so inserts hit random pages and split them. Use NEWSEQUENTIALID(), a sequential UUID version (v7), or keep the UUID as a secondary unique index instead of the clustered key.
Related on SQLly
- SQL data type comparison and converter Free tool
- Generate a UUID in SQL in SQL Server, PostgreSQL, MySQL, SQLite and Oracle Dialect comparison
- Column types for UUIDs and GUIDs in SQL Server, PostgreSQL, MySQL, SQLite and Oracle Dialect comparison
- SQL UUID function Función
- SQL RANDOMBLOB function Función
- SQL SYS_GUID function Función
Map a type to the other four engines
The free type converter maps a type from one engine to its closest equivalent in the others and says where storage, precision or behaviour differ. The desktop app does the same mapping while you edit.