Skip to content
Advertisement

Checking if date in table B is between date in Table A before inserting SQLite

I have a table called Project with start and end dates. I also have a table called Plan which have its own start and end dates column. But I some way to validate that the Plans start/end date is between the matching Project start/end date.

I dont know if its appropriate to add a check when I create the table or when I insert rows to the Plan table. So far I have tried both with no luck.

The following code gives me an error message no such column. Does anyone know how to fix this problem? Thanks in advance.

https://i.stack.imgur.com/UC5Ai.png

Advertisement

Answer

You need a BEFORE INSERT trigger:

and a BEFORE UPDATE trigger:

Also, change the CHECK constraint for the dates to:

or just:

See the demo.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement