Database Relationships: An Interactive Exploration of Keys
Overview
This interactive demo teaches primary and foreign key concepts through a hands-on library database simulation. Add, update, and delete authors and books while observing referential integrity constraints in action. See what happens when you try to create a book with a non-existent author, delete an author with books, or violate other database constraints. Perfect for learning how relational databases maintain data consistency.
Tips
- Try adding a book with an author ID that doesn’t exist to see referential integrity constraints in action
- Delete an author who has books to observe cascading deletes - all their books are automatically removed to maintain consistency
- Leave the ID field blank when adding records to see auto-increment primary keys assign the next available ID automatically
- Update an existing record by entering an ID that’s already in use - the system will modify that record instead of creating a new one
- In production databases, consider ON DELETE CASCADE carefully - it can delete large amounts of related data unintentionally
- Foreign keys prevent orphaned records (books without authors), which is crucial for data integrity in multi-table systems
- Use the reset button to start fresh if you want to explore different scenarios without accumulated changes