From the course: Database Foundations: Data Structures

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Add a foreign key column to a table

Add a foreign key column to a table

From the course: Database Foundations: Data Structures

Start my 1-month free trial

Add a foreign key column to a table

- [Tutor] The first step in creating a foreign key relationship is to add the column that will hold values that relates back to another table. Previously, we created a table for the TwoTrees customers Now we want to add a new table that will store order information that relates to those customers. I'm going to select the TwoTrees database in my SQL server instance and then come up to the file menu and choose open file. Then inside of the exercise files, chapter four folder, we're going to find a file called foreignkey.sql. Let's go ahead and open that up. So the first thing I want to do is review the existing customers table. So let me run my number two here. This shows us our starting position. The customer's table was created with a primary key and it uses the char five data type in this column here for customer ID. If you need a reminder of this, you can go over to the connection sidebar and expand the tables…

Contents