Composite Key

Composite Key

What is a Composite Key?

In the database, a key that has more than one attribute is called a composite key. It is also known as a compound key. A composite key, with regards to databases, is a blend of at least two columns in a table that can be utilized to uniquely distinguish each row in the table. Uniqueness is possibly ensured when the columns are joined; when taken separately the columns don't ensure uniqueness.

How does a Composite Key work?

To create a composite key, from the table we select two Integer type fields and set them as the primary key. Those fields must not have NULL values.

Types and examples:

For understanding composite key, we take example of a table 'Sales'. This table contains 4 columns cstmr_id, order_id, prdct_code, and prdct_count. For such a table we cannot create a composite key because if we take cstmr_id, then one customer can place multiple orders so it cannot be used. order_id can also be not used as it can be applied to multiple products. Same applies to prdct_code and prdct_count.

Thus, it is clear that we need to pick two columns, i.e. cstmr_id, prdct_code and make them composite keys.

Let’s build data apps to transform your business processes

Start for Free
Scale operations fast
Backed by Y Combinator
1250 Missour St San Francisco CA 94010
Copyright © 2023 Acho Software Inc.