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: https://www.cockroachlabs.com/docs/cockroachcloud/quickstart Download the .sql file mentioned in the video: https://drive.google.com/file/d/17lxhGmN8j_-8n73ezlzdAVh2fA5sc206/view?usp=sharing Previous video: what is a foreign key constraint? https://www.youtube.com/watch?v=5kiMg7GXAsY CockroachDB docs on foreign keys https://www.cockroachlabs.com/docs/stable/foreign-key.html