Hello,
I'm new with SqLite but everything was quite easy to understand except foreign keys. Here is my problem, maybe someone could explain it...
I've created two tables:
Create table Table1 (
ID_pk Text PRIMARY KEY,
CHECK(ID_pk like 'P%'));
Create table Table2 (
ID_pk Text PRIMARY KEY,
CHECK(ID_pk like 'M%'));
I would like to create the third table which would have references to foreign keys of these first tables. However, I wanted that fk references would depend on the first letter. Smth like that:
Create table Table3 (
ID Text PRIMARY KEY,
ID_fk Text,
CASE
WHEN (ID_fk like P%)
THEN
(FOREIGN KEY (ID_fk) REFERENCES Table1 (ID_pk)),
WHEN (ID_fk like M%)
THEN
(FOREIGN KEY (ID_fk) REFERENCES Table2 (ID_pk)),
ELSE RAISE(ABORT)
END);
However it doesnt work.. Is it possible to do this? If so, should I use CASE (which means in this case I'm making some errors) or it is possible to solve this problem just with triggers?
Hope somebody could help.. I would really appreciate it...