I have two really simple tables, without any constraint between them:
CREATE TABLE groups (groupId INTEGER PRIMARY KEY AUTOINCREMENT, groupName TEXT)
CREATE TABLE savedRuns (runId INTEGER PRIMARY KEY AUTOINCREMENT, runName TEXT, groupId INT NULL, startTime TEXT, stopTime TEXT, elapsedMilliseconds INT)
Whenever I delete an entry from the group table, the entry in savedRuns which has the same groupId is also deleted. I do not want that!
This is the delete query:
DELETE FROM groups WHERE groupId = 1
I can't understand this behavior as there are no foreign key constrains between the two tables!
I'm using SQlite from the expo-sqlite library in my React Native app.
My final goal is to enabled foreign keys and set the groupId to null in the savedRuns table, but I think I should figure out the first problem first.
I even ran PRAGMA foreign_keys and got 0 as result
All the queries above were fine. The problem was with my
SELECTquery which didn't display the entries without agroupIdin thegroupstable.Changing the
INNER JOINtoLEFT JOINin my SELECT query fixed the issue!