// dialect comparison

Column types for UUIDs and GUIDs in SQL Server, PostgreSQL, MySQL, SQLite and Oracle

Where the UUID can be a real type, and where it is 16 bytes wearing a costume.

Filed under Types & casting

The verdict

PostgreSQL's uuid and SQL Server's UNIQUEIDENTIFIER are real types with byte storage; MySQL and Oracle need BINARY/RAW discipline; SQLite leaves the choice entirely to you. Compact 16-byte storage wins on every index that will hold millions of them.

Where they differ

A UUID is 16 bytes, and how each engine stores those bytes decides index size and join speed. Two engines have native types; the others store BINARY, RAW, TEXT or BLOB.

How each engine writes it

SQL Server

CREATE TABLE t (id UNIQUEIDENTIFIER DEFAULT NEWID());

Native 16-byte type with a readable format. Consider NEWSEQUENTIALID() as the default to reduce index fragmentation.

PostgreSQL

CREATE TABLE t (id UUID DEFAULT GEN_RANDOM_UUID());

Native uuid type: 16 bytes stored, validates the literal, compares efficiently. Avoid TEXT-stored UUIDs unless you need portability.

MySQL

CREATE TABLE t (id BINARY(16) DEFAULT (UUID_TO_BIN(UUID(), 1)));

No native type: CHAR(36) stores the readable form (36 bytes) and BINARY(16) with UUID_TO_BIN stores compact bytes; flag 1 reorders time bits for InnoDB locality.

SQLite

CREATE TABLE t (id TEXT);

No UUID type: store the 36-char text form, or a 16-byte BLOB you format in the app. Declared types only set affinity, so nothing validates the value.

Oracle

CREATE TABLE t (id RAW(16) DEFAULT SYS_GUID());

RAW(16) is the native fit and SYS_GUID() is the natural default; display with RAWTOHEX. CHAR(32) text doubles the size.

Questions that come up

CHAR(36) or BINARY(16) in MySQL?

CHAR(36) is human-readable and joins fine at moderate scale. BINARY(16) is less than half the size, and InnoDB copies the primary key into every secondary index, so the saving multiplies on big tables. Use UUID_TO_BIN/BIN_TO_UUID so you never hand-roll conversions.

Does the GUID order matter for indexes?

Yes: random v4 values scatter inserts across a B-tree, causing page splits. Sequential ids (NEWSEQUENTIALID, UUID_TO_BIN(...,1), or UUIDv7 app-side) keep inserts append-mostly.

Can I use a UUID as a primary key everywhere?

Functionally yes; performance-wise sequential or time-ordered UUIDs (or a bigint surrogate with a uuid lookup) scale better on large tables in every engine.

Keep reading

// write it once, run it anywhere

Switch engines without relearning SQL

SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.