runtime
59 / 139

task Constraints · hard

Enforce delivery-slot rules

Create delivery_slots with slot_id INTEGER PRIMARY KEY, warehouse_id INTEGER NOT NULL referencing warehouses(warehouse_id), slot_date TEXT NOT NULL that must be a valid YYYY-MM-DD date, capacity INTEGER NOT NULL between 1 and 500, and at most one slot per warehouse and date. Insert (1, 1, '2025-05-01', 120) and (2, 1, '2025-05-02', 80). Return slot_id, warehouse_id, slot_date and capacity.

what to return

Columns
slot_idwarehouse_idslot_datecapacity in this order
Rows
2 rows · any order
Skill
Encode business rules as constraints. Refresher: Constraints protect the data contract →

expected result

Your query should return exactly these columns and values. Run it and compare.

expected result2 rows · any order
slot_idwarehouse_idslot_datecapacity
112025-05-01120
212025-05-0280

all 2 rows

data you can query

Logistics dataset: the first 6 rows of each table. Under each column name: the kind of value it holds, and which table it links to. Your queries run on all rows.

warehouses6 columns · 38 rows
warehouse_idnumber · unique idwarehouse_codetextfacility_typetextcitytextstatetextopened_atdate
1FOH1fulfillmentColumbusOH2017-04-19
2FTX2fulfillmentDallasTX2017-03-17
3FCA3fulfillmentSacramentoCA2016-02-04
4FNJ4fulfillmentNewarkNJ2018-11-23
5FGA5fulfillmentAtlantaGA2019-07-04
6FIL6fulfillmentChicagoIL2016-03-21
warehouse_idnumber · unique id
1
warehouse_codetext
FOH1
facility_typetext
fulfillment
citytext
Columbus
statetext
OH
opened_atdate
2017-04-19
warehouse_idnumber · unique id
2
warehouse_codetext
FTX2
facility_typetext
fulfillment
citytext
Dallas
statetext
TX
opened_atdate
2017-03-17
warehouse_idnumber · unique id
3
warehouse_codetext
FCA3
facility_typetext
fulfillment
citytext
Sacramento
statetext
CA
opened_atdate
2016-02-04
warehouse_idnumber · unique id
4
warehouse_codetext
FNJ4
facility_typetext
fulfillment
citytext
Newark
statetext
NJ
opened_atdate
2018-11-23
warehouse_idnumber · unique id
5
warehouse_codetext
FGA5
facility_typetext
fulfillment
citytext
Atlanta
statetext
GA
opened_atdate
2019-07-04
warehouse_idnumber · unique id
6
warehouse_codetext
FIL6
facility_typetext
fulfillment
citytext
Chicago
statetext
IL
opened_atdate
2016-03-21

first 6 of 38 rows · your queries use all of them

solution.sql
 

Hints and the answer are always available. Using them counts the question as solved with help.

Enforce delivery-slot rules — SQL practice · Runtime