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.
Where the UUID can be a real type, and where it is 16 bytes wearing a costume.
Filed under Types & casting
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.
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.
CREATE TABLE t (id UNIQUEIDENTIFIER DEFAULT NEWID());
Native 16-byte type with a readable format. Consider NEWSEQUENTIALID() as the default to reduce index fragmentation.
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.
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.
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.
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.
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.
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.
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.
Four named functions with different versions and shapes, plus one engine that makes you roll your own.
Five engines, five spellings of the column that numbers itself.
Blank-padding is invisible until a join compares CHAR to VARCHAR and stops matching.
SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.