← Back to Constraints
Question 72
Exam Bookings With Every Rule
Exam Bookings With Every Rule
Create a table calledexam_bookingswith six columns and every rule below.idis anINTEGER PRIMARY KEY.student_idis a requiredINTEGERforeign key tostudents(id)withON DELETE CASCADE, so an unknown student is rejected and deleting a student removes their bookings.seat_codeis requiredTEXTand no two bookings may share one.duration_minutesis a requiredINTEGERbetween 30 and 180 inclusive.statusis requiredTEXT, defaulting to'booked', and may only be'booked','sat'or'missed'.notesis optionalTEXT.
Expected result:
Table exam_bookings ✓ id INTEGER PRIMARY KEY ✓ student_id INTEGER NOT NULL ✓ seat_code TEXT NOT NULL ✓ duration_minutes INTEGER NOT NULL ✓ status TEXT NOT NULL DEFAULT 'booked' ✓ notes TEXT ✓ student_id REFERENCES students(id) ✓ UNIQUE (seat_code) ✓ Insert a booking for student 999, who does not exist: rejected (FOREIGN KEY) ✓ Insert a booking with no seat code: rejected (NOT NULL) ✓ Insert two bookings for seat A-01: rejected (UNIQUE) ✓ Insert a 200-minute booking: rejected (CHECK) ✓ Insert a booking with status 'late': rejected (CHECK) ✓ Insert a 180-minute booking with no status or notes: accepted ✓ Insert a booking for student 29, then delete student 29: accepted
Hints4 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 on the left.