What is a primary key in a database?
A primary key is a column (or set of columns) whose value uniquely identifies each row in a database table, and cannot be null or duplicated. It gives every record a stable, unique identity, letting other tables reference it reliably through foreign keys.
The primary key is the anchor of a well-designed table. Common examples are a customer_id, an order_number, or an email that is guaranteed unique. Its rules:
- Unique no two rows share the same primary-key value.
- Not null every row must have one.
- Stable it should not change over a row's lifetime.
Primary keys enable relationships: a foreign key in another table points at a primary key to link records (an order belongs to a customer). They also power indexes that make lookups fast and joins reliable.
When keys are clean, joining data is straightforward; when they are inconsistent or spread across systems that name them differently, connecting records becomes guesswork. iDBQuery reads your schema during introspection to identify primary and foreign keys, then uses them to infer how tables relate. When you ask a plain-language question that spans several tables, or even several sources, it joins on the right keys automatically, writes the SQL, and cites the answer back to the identified rows, so you never have to hand-trace which column links to which.
Updated 2026-06-22