Reputation: 3154
When i run these queries:
create table University ( branch text primary key, region text, enrollment int);
create table Student ( sID int primary key, sName text, average int);
create table Apply ( sID int references Student(sID), branch text references University(branch), major text, decision text);
insert into Apply values ( 123, 'stanford', 'CS', 'Y');
It should return an error because i am inserting a tuple that doesn't have a Corresponding value in the reference table. but when i run these commands, this tuple inersts Successfully. What's wrong with this queries? My DBMS is sqlite and i'm using sqliteman.
Upvotes: 0
Views: 107
Reputation: 51725
You should learn how to enable foreign key support
Quoting docs:
In order to use foreign key constraints in SQLite, the library must be compiled with neither SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER defined. If SQLITE_OMIT_TRIGGER is defined but SQLITE_OMIT_FOREIGN_KEY is not, then SQLite behaves as it did prior to version 3.6.19 - foreign key definitions are parsed and may be queried using PRAGMA foreign_key_list, but foreign key constraints are not enforced. The PRAGMA foreign_keys command is a no-op in this configuration. If OMIT_FOREIGN_KEY is defined, then foreign key definitions cannot even be parsed (attempting to specify a foreign key definition is a syntax error).
Also read sqliteman constraint triggers:
There is one more unsupported SQL feature. Sqlite does not enforce foreign keys and not null constraints.
Upvotes: 1