From the course: SQL Server 2008 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Creating unique constraints - SQL Server Tutorial
From the course: SQL Server 2008 Essential Training
Creating unique constraints
Another kind of constraint you can work with is what's called a unique constraint. Now in fact, we already have one of these on most of our tables. If you have a primary key, you have a unique constraint. That primary key cannot be duplicated. In this case, there can only be one ProductID with 1008 in it. But occasionally, you will want to define another column as being a unique constraint, that the value cannot occur more than once in the entirety of the column in that table. Now right now none of these columns should be made unique. Certainly not UnitsInStock and certainly not Color. That repeats quite a lot. We might have ProductName made unique, but not the way that we work with it. For example, I have a Road-650 58 in Black and I have a Road-650 58 product in Red and a Road-650 58 product in Green. I can't make ProductName unique. What would be interesting, however, is if I could force uniqueness on a combination of the two. What that allows me to do is make sure that they aren't…
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
-
-
-
-
-
-
Planning your database9m 39s
-
(Locked)
Creating a SQL Server database4m 7s
-
(Locked)
Creating tables7m 50s
-
Data types in SQL Server12m 25s
-
(Locked)
Defining keys8m 9s
-
(Locked)
Creating default values4m 39s
-
(Locked)
Creating check constraints2m 25s
-
(Locked)
Creating unique constraints4m 34s
-
Introduction to relationships and foreign keys9m 51s
-
(Locked)
Creating relationships in SQL Server Management Studio8m 14s
-
(Locked)
Database normalization11m 47s
-
(Locked)
Creating computed columns3m 10s
-
-
-
-
-
-
-
-
-
-
-
-