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 - MySQL Tutorial
From the course: MySQL Database Administration
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Creating an index4m 41s
-
(Locked)
The UNIQUE constraint4m 8s
-
(Locked)
The NOT NULL constraint3m 59s
-
(Locked)
Challenge: Indexes and constraints1m 12s
-
(Locked)
Solution: Indexes and constraints9m 24s
-
(Locked)
Stored procedures6m 27s
-
(Locked)
Challenge: Stored procedures2m 3s
-
(Locked)
Solution: Stored procedures4m 23s
-
(Locked)
Triggers7m 50s
-
(Locked)
Challenge: Triggers1m 41s
-
(Locked)
Solution: Triggers5m 8s
-
(Locked)
-
-