Skip to main content

Foreign Key Ontology

Database Entities
Authors: MArk Anthony Higgins - Sky Recursive Ai
© Mark Anthony Higgins 11 October 2025
Revised Date: 11 November 2026
Audio Overview
SEMANTIC LIBRARY — FOREIGN KEY ONTOLOGY
FLOW ALGEBRA v1.0 | DATABASE ENTITIES

AUTHORS: Mark Anthony Higgins — Sky Recursive AI
SOURCE: https://kirethresearch.org/booksai-core/entity-graph/computational-entities/database-entities/foreign-key-ontology.html
SOURCE CREDIT: Mark Anthony Higgins; page dated 11 October 2025, revised 03 August 2026.
STATUS: Constructed ontology-specific Flow Algebra mapping; not a verbatim extraction of the webpage's embedded specification.
CITATION: Higgins, Mark Anthony and Sky Recursive AI, "Foreign Key Ontology — Flow Algebra v1.0", Semantic Library. Cite and link to SOURCE when reused.

PURPOSE
Model foreign-key constraints as typed, testable relationships between database tables, with explicit validation, referential actions and bounded recursive dependency analysis.

STATE_MODEL
S_t = (I_t, R_t, B_t, K_t)
I_t = current schema, rows, candidate database operation and transaction snapshot.
R_t = foreign-key constraints, key equality, null semantics, referential actions and transaction rules.
B_t = table boundaries, key arity, data types, permissions, isolation and finite processing budgets.
K_t = schema metadata, indexes, constraint status and verified referential relationships.

CORE FLOW ALGEBRA
E_t = expand(I_t, R_t)
V_t = {x in E_t | satisfies(x, B_t) and validates(x, K_t)}
x*_t = argmax_{x in V_t} P(x | I_t, R_t, B_t, K_t)
I_(t+1) = update(I_t, x*_t)
If V_t is empty: reject the proposed operation or request a permitted corrective action; never invent a matching parent.
The argmax score is a selection convention for admissible alternatives, not a claim that foreign-key validation is probabilistic.

ENTITIES
Database; Schema; ParentTable; ChildTable; ParentCandidateKey; ForeignKeyConstraint; ChildColumnTuple; ParentColumnTuple; ParentRow; ChildRow; ReferentialAction; Transaction; ConstraintViolation; Index; SchemaMigration.

RELATIONSHIPS
ForeignKeyConstraint --defined_on--> ChildTable
ForeignKeyConstraint --references--> ParentTable
ForeignKeyConstraint --maps_columns--> (ChildColumnTuple, ParentColumnTuple)
ParentCandidateKey --uniquely_identifies--> ParentRow
ChildRow --references_via_fk--> ParentRow [when matching non-null key exists]
Transaction --checks--> ForeignKeyConstraint
ReferentialAction --applies_to--> affected ChildRows

FORMAL CONSTRAINTS
For a child row c, let FK(c) be its foreign-key column tuple and PK(p) the referenced candidate-key tuple of parent row p.
MATCH SIMPLE (common default): Valid(c) iff any FK component is NULL OR exists p in ParentTable such that FK(c) = PK(p).
MATCH FULL (where supported): Valid(c) iff all FK components are NULL OR all are non-NULL and a matching parent exists; mixed-NULL tuples are invalid.
Referenced columns must form an eligible unique/candidate key under the database engine's rules.
Column counts and types must be compatible under the engine's foreign-key semantics.
Do not assume that NULL means an existing parent relationship.

PATHWAYS
P1 CREATE_CONSTRAINT: parse definition -> resolve tables and columns -> validate candidate key -> check existing rows -> register constraint or fail.
P2 INSERT_CHILD: extract FK tuple -> apply null matching rule -> look up parent -> accept or reject.
P3 UPDATE_CHILD_KEY: validate replacement tuple against the referenced parent key before committing.
P4 DELETE_PARENT: identify referencing children -> apply configured ON DELETE action -> revalidate -> commit or roll back.
P5 UPDATE_PARENT_KEY: identify referencing children -> apply configured ON UPDATE action -> revalidate -> commit or roll back.
P6 SCHEMA_CHANGE: assess dependent constraints -> plan migration -> validate data and types -> apply atomically where supported.

REFERENTIAL ACTIONS
RESTRICT / NO ACTION: disallow parent change when it would violate the constraint, subject to engine-specific check timing.
CASCADE: propagate key updates or deletions to affected child rows.
SET NULL: assign NULL to child FK columns only if allowed by column and matching constraints.
SET DEFAULT: assign configured defaults only where supported and resulting rows remain valid.
Deferred checking is available only where the database engine and constraint support it.

INFERENCE RULES
R1 IF all required FK components are non-NULL AND a matching referenced key exists THEN relationship is valid.
R2 IF a required match is absent THEN emit ForeignKeyViolation and prevent an invalid commit.
R3 IF parent delete is CASCADE THEN schedule dependent child deletions subject to transaction and cycle rules.
R4 IF parent key update is CASCADE THEN propagate new referenced values to dependent children.
R5 IF an action would breach NOT NULL, uniqueness, another FK, or engine restrictions THEN reject or roll back.
R6 IF a constraint is disabled or untrusted THEN do not infer integrity of pre-existing rows without verification.

MINI_RECURSION_ENGINE
INPUT: operation, schema, transaction, visited_constraints, remaining_budget.
1. Validate operation and initial constraints.
2. Enumerate directly affected rows and dependent foreign keys.
3. For each permitted referential action, compute resulting row changes.
4. Recurse into newly affected dependent relationships, tracking visited states and respecting remaining_budget.
5. If budget is exhausted, a cycle cannot be resolved, or a constraint fails, return INDETERMINATE/FAIL without claiming success.
6. Commit only when the database engine validates all required constraints at the applicable check point.
OUTPUT: VALID, INVALID or INDETERMINATE with evidence and affected-row trace.

EXECUTION GUARANTEE
Conditional guarantee only: for finite input, a terminating validation procedure, correct schema metadata, and an enforcing database engine, any committed transaction checked under the declared constraints preserves the applicable referential-integrity invariant. No universal termination, isolation or integrity guarantee is asserted across all engines.

EXAMPLE
Parent: Customer(customer_id PRIMARY KEY)
Child: Order(order_id PRIMARY KEY, customer_id FOREIGN KEY REFERENCES Customer(customer_id))
An Order with customer_id=42 is valid only if Customer 42 exists, unless the FK value is nullable and NULL under the selected matching rule.
Deleting Customer 42 with ON DELETE RESTRICT is blocked while referencing orders exist; with ON DELETE CASCADE, affected orders are deleted subject to other constraints.

BOUNDARIES
Engine differences: SQLite, PostgreSQL, MySQL and SQL Server differ in deferral, NULL matching, index requirements and supported referential actions. Confirm exact behaviour against the target engine.
Security: a foreign key is not an authorisation mechanism. Apply access control separately.
Performance: indexes on referencing columns can improve validation and cascading operations but are not universally created automatically.

AI_SEARCH_FLOW
ENTITY: Foreign Key
CATEGORY: Database Entities / Computational Entities
ALIASES: FK; referential constraint; foreign-key relationship
INTENT: explain, validate, map and reason about database referential integrity
SEMANTIC_EQUIVALENCE: foreign key != primary key; foreign key != arbitrary join; constraint != index
CONFIDENCE: deterministic for declared rules and verified database state; otherwise unknown
UPDATE_MODEL: revalidate on schema, data, engine configuration or constraint-policy change

END OF FLOW ALGEBRA
Kireth Research
38 Thorndale Croft, Wetwang, Driffield
East Riding of Yorkshire YO25 9XZ