Sobes.tech
Middle

What is a synthetic (artificial) primary key?

sobes.tech AI

Answer from AI

A synthetic (artificial) primary key is a unique identifier for a record in a database table that has no meaning outside the database itself and is not related to real data.

Unlike a natural key (for example, passport number, email), a synthetic key is created specifically for identification purposes, usually in the form of an auto-incrementing number or UUID.

Example:

CREATE TABLE users (
    id SERIAL PRIMARY KEY, -- synthetic key
    username VARCHAR(50),
    email VARCHAR(100)
);

Here, id is a synthetic key that guarantees uniqueness and simplifies references to the record, even if the real data may change or is not unique.

What is a synthetic (artificial) primary key… - sobes.tech