2010-06-18 11 views

Répondre

1

les travaux suivants fins:

create table table_a (

    id int, 
    file_name varchar(300), 
    folder_id int 
); 

create table table_b (
folder_id int, 
folder_path varchar(300) 
); 

insert into table_a (id, file_name, folder_id) values (1, 'file1.txt', 1); 
insert into table_a (id, file_name, folder_id) values (1, 'file2.txt', 1); 
insert into table_a (id, file_name, folder_id) values (1, 'file2-1.txt', 2); 
insert into table_b (folder_id, folder_path) values (1, 'c:\abc\somefolder\another'); 
insert into table_b (folder_id, folder_path) values (2, 'c:\abcNOT\somefolder\another'); 

delete 
from table_a 
where folder_id in (select folder_id from table_b where substr(folder_path, 1, 7) = 'c:\abc\'); 

select * from table_a; 
0

même idée, mais avec quelques modifications: SQLite reconnaissent l'intégrité référentielle maintenant:

CREATE TABLE TABLE_A ( id int, nom_fichier varchar (300), folder_id int, FOREIGN KEY (ID_fichier) REFERENCES Table_b (ID_fichier) );

CREATE TABLE Table_b ( folder_id int, folder_path varchar (300) );

CREATE TABLE Table_b (ID_fichier, chemin_dossier) VALUES (1, 'c: \ abc \ somefolder \ another'); CREATE TABLE Table_b (ID_fichier, chemin_dossier) VALUES (2, 'c: \ abcNOT \ somefolder \ another'); CREATE TABLE Table_a (id, nom_fichier, ID_fichier) VALUES (1, 'file1.txt', 1); CREATE TABLE Table_a (id, nom_fichier, ID_fichier) VALUES (1, 'file2.txt', 1); CREATE TABLE Table_a (id, nom_fichier, ID_fichier) VALUES (1, 'file2-1.txt', 2);

DELETE FROM Table_a O folder folder_id IN (SELECT folder_id FROM Table_b WHERE dossier_path LIKE 'c: \ abc \%');

SELECT * FROM Table_a;