I have a database made in sqlite3 and have set foreign keys on the loan table to the student table and book table to stop duplicate loans:
using create table:
CREATE TABLE loan(
SudentID INTEGER,
ISBN INTEGER,
out INTEGER,
FOREIGN KEY(SudentID)
REFERENCES student(SudentID)
ON DELETE CASCADE
FOREIGN KEY(ISBN)
REFERENCES book(ISBN)
ON DELETE CASCADE
)
CREATE TABLE student(
SudentID INTEGER PRIMARY KEY,
First TEXT,
Last,
Contact Text,
Year INTEGER)
CREATE TABLE book(
ISBN INTEGER PRIMARY KEY,
Title TEXT,
Price INTEGER,
Qty INTEGER,
Subject TEXT)
If i try to insert a duplicate records into the loan table the foreign key does not prevent it.
Pragma is switched on both in the code and in Firefox database settings.
The version is 2.6.0
My work around is to use Distinct to filter out duplicates but is there any way I can activate them as I use this database as a teaching tool. However the cascade delete
does not work! Why?