Section 1 - Instruction

Now that you understand how primary and foreign keys connect tables, let's explore how they create relationships between tables. Every foreign key creates a specific type of connection.

These relationship types are called "cardinality" - basically, how many records can link to each other.

Engagement Message

Have you noticed that some customers might have multiple orders, but each order belongs to just one customer?

Section 2 - Instruction

Here's how to spot relationship types:

1:1 - Each record connects to exactly one other
1:M - Parent has many children, child has one parent
M:N - Both sides can have multiple connections

The key is asking: "How many can each side have?"

Engagement Message

Does this make sense?

Section 3 - Instruction

Let's start with One-to-One (1:1) relationships. This means each record in Table A connects to exactly one record in Table B, and vice versa.

Think of a person and their social security number - each person has one SSN, each SSN belongs to one person.

Engagement Message

Can you think of another real-world example of a 1:1 relationship?

Section 4 - Instruction

One-to-Many (1:M) relationships are the most common. One record in the "parent" table connects to multiple records in the "child" table.

Like our customers and orders: one customer can have many orders, but each order belongs to one customer.

Engagement Message

What's another example where one thing can have many related items?

Section 5 - Instruction

Here's how one-to-many looks:

One customer has three orders. The foreign key appears on the "many" side.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal