← Back to CREATE TABLE
Question 93
Permits That Vanish With the Student
Permits That Vanish With the Student
Createparking_permits:idINTEGER PRIMARY KEY;student_idINTEGER NOT NULLthatREFERENCES students(id)withON DELETE CASCADE;plateTEXT NOT NULL UNIQUE; andexpires_onTEXT(optional). The cascade means that when a student row is deleted, their permits are deleted with it instead of blocking the delete: the checker gives student 1 a permit and then deletes student 1, which must succeed. Two permits for the same plate must be refused.
Expected result:
Table parking_permits ✓ id INTEGER PRIMARY KEY ✓ student_id INTEGER NOT NULL ✓ plate TEXT NOT NULL ✓ expires_on TEXT ✓ student_id REFERENCES students(id) ✓ UNIQUE (plate) ✓ Deleting student 1 after giving them a permit: accepted ✓ Two permits for plate ABCD 123: rejected (UNIQUE) ✓ A permit for student 99: rejected (FOREIGN KEY) ✓ A permit with no expiry date: accepted
Hints3 available
Sign in to use hintsTopics:
CREATE TABLE
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 on the left.