From the course: Introduction to SQLite

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Enforcing relationships between tables

Enforcing relationships between tables - SQLite Tutorial

From the course: Introduction to SQLite

Enforcing relationships between tables

- [Instructor] To enforce relationships between tables, we need a way to link those tables together. We can do that by using columns that have matching values in both tables. Names aren't great choices for linking tables because two rows could have the same name associated with them, and names do change, so we need something immutable that remains constant for all time. Every sqlite table has a hidden column called RowId. This offers a possible way of uniquely identifying a row. The RowId is automatically created for you, and it consists of an integer value that is unique for each row. However, if you delete rows, it will create gaps in the sequence and old RowIds are not reused. As you can see here, we've deleted one row, inserted another, and that creates a gap between one and three. Two will never get reused in this table. You can also declare a primary key column when you define a table. This is similar to unique…

Contents