Primary & Foreign Keys Demo

Interactive exploration of database relationships and referential integrity

Authors Table

Primary Key: id

ID (PK) Name Actions

Books Table

Foreign Key: authorId → Authors(id)

ID (PK) Title Author ID (FK) Actions

About This Demo

Key Concepts
  • Primary Key (PK): Uniquely identifies each row in a table
  • Foreign Key (FK): References a primary key in another table
  • Referential Integrity: Ensures relationships remain consistent
  • Cascading Delete: Deleting an author also deletes their books
Try These Actions
  • Add a new author, then add books for that author
  • Try to add a book with a non-existent author ID (will show error)
  • Delete an author and watch their books cascade delete
  • Update an existing author or book by entering their ID
  • Leave ID blank to auto-generate the next available ID