Can a table have multiple keys?

Yes, a table can have multiple keys. In the context of databases, this is often referred to as a composite key or a primary key that consists of multiple columns. A composite key is used to uniquely identify a record in a table by combining two or more columns.

For example, consider a table that stores information about orders:

CREATE TABLE Orders (
    order_id INT,
    product_id INT,
    customer_id INT,
    PRIMARY KEY (order_id, product_id)
);

In this example, the combination of order_id and product_id serves as the composite primary key, ensuring that each order for a specific product is unique.

0 Comments

no data
Be the first to share your comment!