mercredi 21 janvier 2015

how to delete item in Cascaded manner

I have an application in that i am using SQLite DB to cache the files and folders. SQL query for creating tabel looks as bellow.



CREATE TABLE b
(
Id INTEGER PRIMARY KEY,
ParentId INTEGER NOT NULL,
FileName VARCHAR(260) NOT NULL,
FOREIGN KEY(ParentId) REFERENCES id ON DELETE CASCADE
);


Folder structure looks like



Folder1
Folder11
file1
file2
file3
file4
Folder12
file121
file122
Folder13
Folder2
Folder21
Folder22
Folder3
Folder31
Folder32
Folder33
Folder34


My requirement is:


If i delete a folder then all the childs of that folders needs to be deleted.


for that i written a query



DELETE FROM a WHERE ParentId=x;


But is not working. Is there any mistake in sql query.


Aucun commentaire:

Enregistrer un commentaire