ACID transactions
ACID transactions are the four guarantees that keep database changes correct: atomicity, consistency, isolation, and durability. They make s...
Read definitionA composite key uses two or more columns together to identify a row. No column is unique on its own, but the combination is. You meet them in junction tables like order plus product, and they trade off against a single surrogate key once the key gets wide.
A composite key uses two or more columns together to identify a row. No single column is unique on its own, but the combination is. It is the multi-column version of an ordinary primary key or unique constraint.
The rule holds in every relational database: values can repeat within any one column, but each full combination of the key columns must be unique. Uniqueness lives in the set of columns, not in any single member.
The most common home for a composite key is a junction table, also called a bridge table, which records a many-to-many relationship. An order can contain many products, and a product can appear on many orders, so the link gets a table of its own.
CREATE TABLE order_items (
order_id integer NOT NULL,
product_id integer NOT NULL,
quantity integer NOT NULL,
PRIMARY KEY (order_id, product_id)
);The primary key on (order_id, product_id) lets order 10 sit on many rows and product 55 sit on many rows, while it blocks the same product from being listed twice on the same order. The business rule now lives in the schema, and splitting a many-to-many into its own table like this is what database normalisation asks for.
A composite key is backed by a single multi-column index, and the order of the columns decides which queries it can speed up. A database reads such an index from left to right, so it can use any leftmost prefix of the columns but not an arbitrary subset.
Say the key is (customer_id, order_date). A lookup on customer_id alone uses the index, and so does a lookup on both columns together. A lookup on order_date alone cannot, because it is not a leftmost prefix. Put the column you filter on most often first.
A composite key is built from columns that already carry business meaning, close to what a candidate key or business key describes. A surrogate key is the opposite, a single invented column, usually an auto-incrementing integer or a UUID, that stands in for the whole combination.
The trade-off appears the moment other tables point at the row. A foreign key has to repeat every column of the key it references, matched by number and type, so a three-column composite key becomes three columns in every child table and three conditions in every join. A surrogate key collapses that to one column and one join.
So the wider the composite key, or the more tables that reference it, the more a surrogate key earns its place. A data warehouse often keeps both: a surrogate key for joins, plus a unique constraint on the natural combination so duplicate rows still cannot slip in.
Member columns should be stable. The combination is the row's identity, so if one column can change, the identity changes with it, and every foreign key pointing at the row has to change too.
Nulls behave differently per constraint. A primary key forbids nulls in all of its columns. A unique constraint allows them, and because two nulls are not treated as equal, it can let through rows you expected it to block.
ACID transactions are the four guarantees that keep database changes correct: atomicity, consistency, isolation, and durability. They make s...
Read definitionAnomaly detection automatically flags data points, events, or patterns that do not fit normal behaviour. It can catch odd invoices, machine ...
Read definitionApache Airflow is an open-source workflow orchestrator for batch-oriented data pipelines. You define workflows as Python code, connect tasks...
Read definitionApache Spark is an open-source engine for large-scale data processing. It lets teams write SQL, Python, Scala, Java, or R code while Spark d...
Read definitionAn API, or Application Programming Interface, is a contract that lets software talk to other software. In a data context, APIs are how conne...
Read definition
Seven new Data Panda connectors from June 2026, with practical reporting ideas for stock, finance, ticketing, route planning and operations.
Test data ideas fast with pretotyping. Learn how to validate concepts in days, avoid over-engineering, and build what truly adds value.