, , - . , , - .
Create Table Reservations
(
EventId ... not null References Events ( Id )
, SeatNumber varchar(10) not null
, Expiration datetime not null
, CustomerId ... not null References Customers( Id )
, Constraint FK_Reservations_Seats
Foreign Key( EventId, SeatNumber )
References EventSeats( EventId, SeatNumber )
)
Create Table EventSeats
(
EventId ... References Events ( Id )
, SeatNumber varchar(10) not null
, CustomerId ... null References Customers( Id )
, PurchaseDate datetime not null
)
- , . , :
Select S.EventId, S.SeatNumber
From EventSeats As S
Where S.EventId = ...
And S.CustomerId Is Null
And Not Exists (
Select 1
From Reservations As R
Where R.EventId = S.EventId
And R.SeatNumber = S.SeatNumber
And R.Expiration > CURRENT_TIMESTAMP
)
- , . , . , , , , 10 , . , EventSeats , .