From the course: Database Foundations: Data Structures
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Composite keys
From the course: Database Foundations: Data Structures
Composite keys
- [Instructor] When establishing the unique primary key for each table, you might need to look beyond a single column. Primary keys can be made up of multiple attribute columns that together provide the unique identifier for a row. And these are called composite keys. Often composite keys are useful when you have a situation where you want to make sure that two rows never have the same combination of values across two or more columns. For instance, in a hotel database, you wouldn't want to rent out the same room twice, on the same night, to two different guests. By establishing a composite key, that involves the check-in date and room number columns, we can guarantee that we don't double book a room. Let's experiment with how that works by mocking it up in Azure Data Studio. I'm going to right-click on my twotrees database in the SQL Server instance and open up a new query window. Let's first create a table to hold some…
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)
Purpose of a primary key3m 55s
-
Establish the table's primary key6m 59s
-
Natural keys2m 42s
-
(Locked)
Composite keys5m 33s
-
(Locked)
Surrogate keys4m 40s
-
(Locked)
Challenge: Add a primary key to a table53s
-
(Locked)
Solution: Add a primary key to a table5m 51s
-
(Locked)
Solution: Alter a table's design6m 43s
-
(Locked)
-
-
-
-
-