FOREIGN KEY parent update/delete and table-drop checks
Implement the following agreed behavior through the shared engine interfaces.
Contract
| Field | Value |
|---|---|
| Specification | KEY-003 |
| Module | constraints |
| Scope | Required implementation or delivery |
| Milestone | M2, due 2026-12-20 |
| Owner role | SQL / frontend — teammate to claim |
| Implementation | Planned; scaffold only |
| Contract review | Team review required before implementation |
Interface
ConstraintManager.validateReferencedParent(change)
These are proposed C++ design contracts, not an already implemented API. Shared types and ownership define the intended module boundaries.
Dependencies
- KEY-002: Single/composite FOREIGN KEY child insert and update
- DML-003: UPDATE constant assignments and actual changed-row count
- DML-004: DELETE filtered rows and delete all
Acceptance checklist
- [ ] Reject deletion/key-changing update of a referenced parent
- [ ] Allow changes to unrelated parent fields and removal of unreferenced rows
- [ ] Track several referencing tables and composite keys without full dataset loads
Setup data
Run this in a fresh isolated data directory before the example. Setup commands emit their own results; the expected block below covers only the listed input.
CREATE DATABASE demo;
USE demo;
CREATE TABLE parent (id INT NOT NULL, PRIMARY KEY (id));
INSERT INTO parent VALUES (1);
CREATE TABLE child (pid INT NOT NULL, FOREIGN KEY (pid) REFERENCES parent(id));
INSERT INTO child VALUES (1);
Input
DELETE FROM parent WHERE id = 1;
Expected output
!ERROR
foreign key violation
@
Where no ORDER BY appears, row order is not guaranteed. Error message text is illustrative; required diagnostic keywords and result framing are binding.
Rejections and state
- Parent still referenced -> foreign; retain row and indexes
Verification
Completion rule
Link this spec and its GitLab issue in an MR into develop. Include relevant Linux evidence, obtain the other teammate’s review, merge, delete the feature branch, and close the issue. A page describes intended behavior; the GitLab issue and merged code determine completion.