CJCoding With Joseph
15free / daySign inCreate account

Permits That Vanish With the Student

Create parking_permits: id INTEGER PRIMARY KEY; student_id INTEGER NOT NULL that REFERENCES students(id) with ON DELETE CASCADE; plate TEXT NOT NULL UNIQUE; and expires_on TEXT (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
Topics:
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.