CJCoding With Joseph
15free / daySign inCreate account

Exam Bookings With Every Rule

Create a table called exam_bookings with six columns and every rule below. id is an INTEGER PRIMARY KEY. student_id is a required INTEGER foreign key to students(id) with ON DELETE CASCADE, so an unknown student is rejected and deleting a student removes their bookings. seat_code is required TEXT and no two bookings may share one. duration_minutes is a required INTEGER between 30 and 180 inclusive. status is required TEXT, defaulting to 'booked', and may only be 'booked', 'sat' or 'missed'. notes is optional TEXT.

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
Topics:
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.