# 1.10: Foreign Keys

Now, you're going to learn about foreign keys and primary keys. Click [here](https://www.youtube.com/watch?v=TpKcAmaaBts) to watch a video introducing these concepts. SQL Server is used in the video instead of Visual Studio, so the specific steps to set up tables and keys are different. However, the underlying concept is the same and can be applied to T-SQL. After watching the video, you can follow [this link](https://docs.microsoft.com/en-us/sql/relational-databases/tables/primary-and-foreign-key-constraints) to read about establishing constraints with T-SQL.<br>

Use what you've learned to complete the following exercise. Replace the **XXXXXXXX**s with the correct information to complete the query below:

![Purchase Table Challenge](https://1712903417-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YgF0bbt1vxBgc5B%2F-LAU8dTUP51jQtyZvnhQ%2F-LAU8rmBSO74ZSg0qD9k%2F1.10tsql1.png?generation=1524162331882191\&alt=media)

To see the solution for this challenge, click on [1.12 Solutions](https://eleven-fifty-academy.gitbook.io/sql-101-basics/1.12-solutions#110-foreign-keys-solution).\
&#x20;Once you have double-checked your solution, run the query in Visual Studio and refresh your database. You should see a "Purchases" table, which you'll use in the next lesson.

![Purchase Table Result](https://1712903417-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YgF0bbt1vxBgc5B%2F-LAU8dTUP51jQtyZvnhQ%2F-LAU8rn_HA7vb_LM28Sk%2F1.10tsql2.png?generation=1524162331863154\&alt=media)

Then, continue to [Part 1.11: Join](https://eleven-fifty-academy.gitbook.io/sql-101-basics/part-1-transact-sql/1.11-join).
