From the course: Microsoft SQL Server 2022 Essential Training
Unlock this course with a free trial
Join today to access over 24,500 courses taught by industry experts.
Unique constraints - SQL Server Tutorial
From the course: Microsoft SQL Server 2022 Essential Training
Unique constraints
- [Instructor] There are any number of reasons why you would want to enforce values in a record to be unique from all other records in the same table. The table's primary key column is just one example of a column that needs to maintain unique values. It's probably a bad idea to have two different products with exactly the same name because that would make it confusing for customers that are trying to place an order. Or maybe you want to use email addresses as a way to identify individual people when posting reviews on a recipe website. We can have SQL Server monitor the values that are being stored in our table, and by identifying individual columns that should not allow duplicate values between records, we can have the server enforce this rule on the data. Let's take a look inside of the products table for the Red30Tech database. Going to expand it open here and then expand the columns folder. In this table, we…
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
-
-
-
-
-
-
Choose appropriate data types2m 46s
-
(Locked)
SQL Server data type options7m 19s
-
(Locked)
Automatically assign record identities4m 54s
-
(Locked)
Primary key fields4m 35s
-
(Locked)
Establish a default value5m 1s
-
(Locked)
Check constraints5m 10s
-
(Locked)
Unique constraints6m 23s
-
(Locked)
Foreign keys4m 16s
-
(Locked)
Create a foreign key column5m 16s
-
(Locked)
Create relationships between tables5m 6s
-
-
-
-
-
-
-