Technology Encyclopedia Home >What is the difference between a composite key, primary key and foreign key?

What is the difference between a composite key, primary key and foreign key?

A primary key is a unique identifier for each record in a table. It ensures that each record can be uniquely identified and prevents duplicate records. For example, in a table of students, the student ID could be the primary key.

A foreign key is a field in one table that references the primary key of another table. It establishes a relationship between the two tables. For instance, in a table of orders, the customer ID could be a foreign key that references the primary key (customer ID) in a table of customers.

A composite key is a combination of two or more columns that together uniquely identify each record in a table. For example, in a table that records student course enrollments, a composite key could be a combination of the student ID and the course ID, as each combination of student and course is unique.

In the context of cloud computing, databases are often managed and scaled using cloud services. For example, Tencent Cloud offers a variety of database services that support these key concepts, allowing for efficient data management and retrieval in cloud environments.