Simulate a conditional unique rule
SQL
Hard
7 views
Problem Description
In Seats(bus_id, seat_no, status), seat_no should be unique per bus only for active seats (status='ACTIVE'). Write a SQL approach that enforces it using a separate table ActiveSeats and FK/PK.
Output Format
DDL statement(s)
Sample Test Case
Input:
Seats(bus_id, seat_no, status)
Constraints
Use a helper table to enforce partial uniqueness
Official Solution
CREATE TABLE ActiveSeats (bus_id INT NOT NULL, seat_no INT NOT NULL, PRIMARY KEY (bus_id, seat_no));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!