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.

Composite keys

Composite keys

From the course: Database Foundations: Data Structures

Start my 1-month free trial

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…

Contents