From the course: MySQL Database Administration

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

The UNIQUE constraint

The UNIQUE constraint

- [Instructor] Alright, next we're going to be talking about the unique constraint. So in MySQL, we can prescribe which columns we want to allow to have repeating values and which columns must only contain unique values. Adding a unique constraint, it's very easy. We can do this using Workbench's UI or we can do it using SQL code, like we do with a lot of other things. Including a unique constraint on columns that should not repeat is a great way that we can ensure data integrity. And in general, this is a very good best practice as you're designing a database. Let's jump into Workbench and walk through a quick example. Let's use our thrift shop schema for this example. And first let's just show you what we have in the inventory table. So let's take a look at that. And we see inventory ID, inventory name, and the number that's in stock. So let's jump into that table so we can see some of the properties on the columns. We'll go into Inventory and we'll use the little Workbench wrench…

Contents