How to delete data from multiple tables in sqlite?

I am using sqlite database to store data. I have three tables: Invoice, InvRow, Invdetails.

Relations between tables:

Invoice.Id = InvRow.InvId
InvRow.Id = Invdetails.RowId 

I need to delete related records from three tables using one query. How can i do this? Any help?

+5
source share
2 answers

SQLite prior to version 3.6.19 (2009 Oct 14) does not support foreign key constraints, but you can use triggers to maintain relational integrity .

Starting with version 3.6.19 , SQLite supports the correct foreign key constraint with sentences ON [UPDATE|DELETE] CASCADEthat will do what you want.

+8

Alex B , . .

, , . , movie_providers, movie_providers - , , .

: DELETE FROM movies, movie_pproviders WHERE movie.id = movie_providers.movie_id AND [my constraint]

2

DELETE FROM movies WHERE [my constraint]
DELETE FROM movie_providers where movie_id NOT IN (SELECT DISTINCT id FROM movies)

, movie_providers. , .

+4

All Articles