SQL

Reject impossible maintenance jobs

P99 was registered, but J1 lost its duration

An otherwise readable inspection job points to an absent pump. Protect the relationship and its duration rule together.

BOTIE

The changed fixture supplies the missing parent but gives J1 a null duration. Why should the failing identity change?
The inputs we are comparing

Proposed jobs

One job points to an absent pump

[
  {
    "id": "J1",
    "asset_id": "P7",
    "minutes": 20
  },
  {
    "id": "J2",
    "asset_id": "P99",
    "minutes": 10
  }
]

The parent is added but duration is missing

[
  {
    "id": "J1",
    "asset_id": "P7",
    "minutes": null
  },
  {
    "id": "J2",
    "asset_id": "P99",
    "minutes": 10
  }
]

Registered asset IDs

One job points to an absent pump

  1. 0P7
  2. 1P8

The parent is added but duration is missing

  1. 0P7
  2. 1P99
Result for one job points to an absent pump
  1. 0J2
Choose an explanation to test
The asset exists but the duration is negative

This check uses the pieces from “Check each job against its parent and duration”.

BOTIE

P2 is registered. J7 proposes minus five minutes and J8 proposes twelve. Predict the rejected IDs.
Proposed jobs
[
  {
    "id": "J7",
    "asset_id": "P2",
    "minutes": -5
  },
  {
    "id": "J8",
    "asset_id": "P2",
    "minutes": 12
  }
]
Registered asset IDs
  1. 0P2

Use a number, text, or an array matching the requested result. For a matrix, put each row in brackets. Saving your prediction runs your current construction on these inputs and checks the earlier examples too.

Build a construction in the workspace above first. This case will test those pieces.

Why does a foreign key not establish which technician is allowed to see the asset?

Separate data validity from authorisation, and test both at their proper boundaries.

The widget illustrates selected invariants. The SQL table additionally enforces uniqueness and database-level relationships.

Work through the SQL challenges →
Continue the courseWhy Must a Pump Move Be Edited on Every Job? →
← What Does One Equipment Record Promise?