Skip to main content

How to Create Tables with Foreign Keys in SQL

Foreign keys are important for maintaining referential integrity in any SQL-based database. But how can you create tables with foreign keys, and more importantly, how can you ensure they are correctly updated when changes are made in the referencing table? 00:00 What is a foreign key 0:09 Setup 0:49 Creating a SQL table with foreign keys 2:03 Setting update and delete rules 2:54 Making changes after creating a table 3:11 Review Set up a free CockroachCloud account and spin up a database: Download the .sql file mentioned in the video: Previous video: what is a foreign key constraint? CockroachDB docs on foreign keys