MySQL DatabaseLesson 54Free preview
MySQL Unique
This lesson is part of MySQL · All levels
Summary
The UNIQUE constraint ensures that each value in the column is different, so that the double data cannot be stored. Unlike the primary key, a table may have multiple UNIQUE columns and on MySQL the value NULL remains allowed (and is considered to be non-equal). UNIQUE is often used for email, identity number, or code that must be unique.
Key points
- UNIQUE prevents duplicate values on columns or column combinations
- One table can have many unique constraints
- MySQL allows more than one NULL in the UNIQUE column
- It can be defined in one column or multiple columns at once.
- Name the constraint so it's easy to reference when it's deleted.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.