In this tutorial we look at Composite Keys and how they should be created to benefit performance. With the lesson broken down into chapters it will make easy learning for you.
Some people may refer to creating Composite Keys as 'Creating Primary Keys on more than one column'. Basically - thats correct! A Composite Key is a Primary Key which consists of more than one column.
Here we look at how you should create Composite Keys. Firstly, we need to understand what sort of data would be going into the table and furthermore, how will it be searched? How will the application be accessing this data? If for example we will be searching for it by FullName, then having the Composite Key on Address wouldn't be very beneficial. We go over that in this SQL lesson.
During the tutorial we use the SQL Server Execution plan to see how our searches are being searched for by the SQL Server Engine. The execution plan tells us the cost of the query, the number of rows that have been read, whether it used an index and how - it's fantastic stuff!
I like to also stick to naming conventions with any Indexes and Primary Keys that are created and we follow that here. Any questions then let me know in the comments below
Content:
00:00 Lesson Overview
00:28 Lets look at the Data
01:33 Creating our test Data
02:15 What is a Composite Key?
03:05 How is the Data ordered?
03:35 How to Create a Composite Key
04:17 SQL Execution Plan