You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement CASCADE behavior enforcement for FOREIGN KEY constraints #2336
AlaSQL currently parses CASCADE syntax but does not enforce the behavior. When a parent row is deleted or updated, child rows with ON DELETE CASCADE or ON UPDATE CASCADE are not automatically affected.
What needs to be implemented
ON DELETE actions:
CASCADE: When a row in the parent table is deleted, automatically delete all rows in child tables that reference it
SET NULL: Set foreign key columns to NULL in child tables when parent is deleted
SET DEFAULT: Set foreign key columns to their default value when parent is deleted
RESTRICT: Prevent deletion of parent row if child rows exist
NO ACTION: Same as RESTRICT per SQL-99 standard
ON UPDATE actions:
CASCADE: When parent key is updated, update matching foreign keys in child tables
SET NULL: Set foreign key to NULL when parent key is updated
SET DEFAULT: Set foreign key to default when parent key is updated
RESTRICT: Prevent update of parent key if child rows exist
NO ACTION: Same as RESTRICT per SQL-99 standard
Implementation areas
Modify DELETE statement handler (src/74delete.js) to check for child tables and apply CASCADE actions
Modify UPDATE statement handler (src/74update.js) to check for child tables and apply CASCADE actions
Store foreign key metadata including ondelete/onupdate actions in table definition during CREATE TABLE
Add validation for RESTRICT actions before allowing delete/update
Handle circular dependencies and prevent infinite loops
The NIST SQL Test Suite expects the SQL-92 default for a foreign key without ON DELETE or ON UPDATE, which is NO ACTION: deleting or changing a parent key that a child row still uses fails, and nothing changes. 27 checks in 14 files depend on it (cdr008.sql ... cdr011.sql, cdr022.sql, ...). Reproduced on develop (38bf3c3):
alasql('CREATE TABLE p (id CHAR(2) PRIMARY KEY)');alasql("INSERT INTO p VALUES ('E1'), ('E2')");alasql('CREATE TABLE c (pid CHAR(2) REFERENCES p(id))');alasql("INSERT INTO c VALUES ('E1')");alasql("DELETE FROM p WHERE id = 'E1'");// 1, the child row now points at nothingalasql("UPDATE c SET pid = 'E9'");// Foreign key "E9" not found in table "p" (the child side is checked)
Expected: the DELETE fails with an integrity constraint violation (SQLSTATE 23000) and p keeps E1.
Activity
mathiasrw commentedon Oct 21, 2026
The NIST SQL Test Suite expects the SQL-92 default for a foreign key without
ON DELETEorON UPDATE, which isNO ACTION: deleting or changing a parent key that a child row still uses fails, and nothing changes. 27 checks in 14 files depend on it (cdr008.sql...cdr011.sql,cdr022.sql, ...). Reproduced ondevelop(38bf3c3):Expected: the
DELETEfails with an integrity constraint violation (SQLSTATE 23000) andpkeepsE1.