Junior
What is a primary key? Can it be composite? Provide an example of a composite primary key.
sobes.tech AI
Answer from AI
A primary key is a unique identifier for a record in a database table. It guarantees that each row can be uniquely identified.
A primary key can be composite, meaning it consists of multiple columns that together form a unique identifier.
Example of a composite primary key:
CREATE TABLE Orders (
order_id INT,
product_id INT,
quantity INT,
PRIMARY KEY (order_id, product_id)
);
Here, the uniqueness of the record is determined by the combination of order_id and product_id.