Advertisement
Google Ad Slot: content-top
MySQL UNIQUE
MySQL UNIQUE Constraint
The UNIQUE constraint in MySQL ensures that all values in a column or a set of columns are distinct (no duplicates). It is commonly used to prevent duplicate data in database tables.
A PRIMARY KEY constraint automatically has a UNIQUE constraint.
However, you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.
UNIQUE Constraint on CREATE TABLE
Explanation:
email→ Ensures no two students have the same email.phone_number→ Namedunique_phoneto ensure phone numbers are unique.
You can apply the UNIQUE constraint to multiple columns, ensuring the combination of values is unique.
Explanation:
- No student can enroll in the same course more than once.