Library Loans Follow the Student
mediumQuestion 71Create a table called library_loans with four columns: id (an INTEGER PRIMARY KEY), student_id (INTEGER, required, a foreign key to students(id)), book (TEXT, required) and due_on (TEXT, required). A loan for a student id that does not exist must be rejected. When a student is deleted, their loans must disappear with them: declare the foreign key with ON DELETE CASCADE, so that deleting a student who still has a loan succeeds instead of failing.
Expected result
Table library_loans ✓ id INTEGER PRIMARY KEY ✓ student_id INTEGER NOT NULL ✓ book TEXT NOT NULL ✓ due_on TEXT NOT NULL ✓ student_id REFERENCES students(id) ✓ Insert a loan for student 999, who does not exist: rejected (FOREIGN KEY) ✓ Insert a loan for student 28: accepted ✓ Insert a loan for student 30, then delete student 30: accepted
Hints3 available
Sign in to use hintsTopics
Constraints
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sel, ins, desc)
Results
Run your SQL to see every statement's output here, then how it compares with the expected answer.
Not sure what is in a table? SHOW TABLES lists them and DESCRIBE students shows the columns, or open the database browser under the question.