From the course: Database Foundations: Data Structures

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Unique constraints

Unique constraints

From the course: Database Foundations: Data Structures

Start my 1-month free trial

Unique constraints

- [Instructor] Unique constraints apply to columns where you want to guarantee that every row stores a value that's different from every other row. Primary keys are an example of one unique constraint, but you can also apply them to other columns in your table. Unlike the null constraint that's added to the column specification when creating or altering a table, unique constraints are added to a table index. If you think about it, it makes sense that the RDBMS would do it this way. With an index, the database server can quickly find out whether a value has been used before or not, even if the table has millions of rows in it. It doesn't need to read every existing row when a new row is entered. It can just review the index to make sure that the new value is unique. Let's suppose that I want to make sure that every company name in the customers table is unique. We're already enforcing that rule with the primary key column,…

Contents