A primary key is a column, or combination of columns, that uniquely identifies every row in a table. Its values must be unique and cannot be null.
Why it matters
Primary keys give each record a stable identity, so other tables can reference it through foreign keys and updates can target exactly one row. Databases automatically index the primary key, which makes lookups by it very fast. Choosing a good key affects storage size, insert performance, and how easily you can merge or shard data later.
Example
CREATE TABLE users (
id BIGINT PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
name TEXT
);
id identifies the row. email is also unique but is a natural attribute that may change, so it is a poorer primary key.
Common mistakes
- Using a value that can change, such as an email address or phone number, as the key.
- Using a small integer type that eventually overflows on a growing table.
- Leaving a table without any primary key, which complicates replication and duplicate cleanup.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.