Section 1 - Instruction

Last time we learned to enforce data quality with NOT NULL and DEFAULT. Now let's tackle uniqueness! Sometimes you need to guarantee that certain values never appear twice.

Think about email addresses - would you want two customers with identical emails?

Engagement Message

What problems could duplicate emails cause in a customer database?

Section 2 - Instruction

The UNIQUE constraint prevents duplicate values in a column. It's like having a bouncer that checks "Have I seen this value before?" and blocks repeats.

Once someone registers with "john@email.com", nobody else can use that same address.

Engagement Message

Besides email, what other customer information should be unique?

Section 3 - Instruction

Adding UNIQUE is simple - just include it in your column definition:

Now both email and phone must be one-of-a-kind across all customers.

Engagement Message

What happens if you try inserting two customers with the same phone number?

Section 4 - Instruction

Sometimes uniqueness spans multiple columns together. A student can take multiple courses, and a course can have multiple students, but each student-course combination should be unique.

This prevents accidentally enrolling the same student in the same course twice.

Engagement Message

Can you think of other situations where multiple columns together should be unique?

Section 5 - Instruction

Multi-column uniqueness uses table-level constraints. List the columns in parentheses:

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