Bonjour,

Voilà je dois effectuer toutes ces requêtes de suppression :

delete from BUGZILLA_DEPENDENCIES where DEPENDSON in (select BUGZILLA_ID from BUGLIST_VIEW where CUSTOMER_ID in (1425, 2122));

delete from BUGZILLA_DEPENDENCIES where BLOCKED in (select BUGZILLA_ID from BUGLIST_VIEW where CUSTOMER_ID in (1425, 2122));

delete from SC_BUGZILLA where BUGZILLA in (select BUGZILLA_ID from BUGLIST_VIEW where CUSTOMER_ID in (1425, 2122));

delete from BUGZILLA where id in (select BUGZILLA_ID from BUGLIST_VIEW where CUSTOMER_ID in (1425, 2122));

delete from EBSRD_EBSCUST where EBSCUST IN (select ID from EBSCUST where CUSTOMER in (1425, 2122));

delete from EBSCUST where CUSTOMER in (1425, 2122);

delete from SC_SR where SUPPORTCENTER in (select ID from SUPPORTCENTER where customer in (1425, 2122));

delete from SUPPORTCENTER where customer in (1425, 2122);

delete from EBSRD  where CUSTOMER in (1425, 2122);

delete from CUSTOMER where id in (1425, 2122);

Actuellement ma fonction delete, ne contient que la dernière ligne de suppresion mais je dois supprimer toutes les autres pour que la suppression s'effectue avec succès :

public function delete($id){
  $req = $this->db->prepare('DELETE FROM CUSTOMER WHERE id = :id');
  $req->bindParam(':id', $id, PDO::PARAM_INT);
  $req->execute();
  }

Je n'ai pas envie de créer une fonction par delete, je suis assez mauvais en sql..

Est-il possible d'enchainer tous mes deletes dans une même requête ou alors à défaut dans une même fonction ou dois-je créer une fonction par delete ?

Merci d'avance.

3 réponses


Huggy
Réponse acceptée

je vois beaucoup de tables qui dépendent de customer
en mettant des contraintes d'intégrité référentielle et une suppression en cascade
il suffit juste de supprimer le customer et le reste se supprime automatiquement en cascade
reste à voir le temps que ça prend par rapport à des requêtes simultanées.

Nicolas Delage
Auteur
Réponse acceptée

Désolé du retard de réponse, j'ai ajouté un index pour la table customer me permettant d'exécuter ma fonction quasi instantanément !
Mais ton idée est intéressante, je vais essayé de me pencher dessus.

Merci !

J'ai pour le moment procédé de cette façon... :

public function delete($id){

        $req = $this->db->prepare('delete from BUGZILLA_DEPENDENCIES where DEPENDSON in (select BUGZILLA_ID from BUGLIST_VIEW where CUSTOMER_ID = :id )');      
        $req2 = $this->db->prepare('delete from BUGZILLA_DEPENDENCIES where BLOCKED in (select BUGZILLA_ID from BUGLIST_VIEW where CUSTOMER_ID = :id )');       
        $req3 = $this->db->prepare('delete from SC_BUGZILLA where BUGZILLA in (select BUGZILLA_ID from BUGLIST_VIEW where CUSTOMER_ID = :id )');                
        $req4 = $this->db->prepare('delete from BUGZILLA where id in (select BUGZILLA_ID from BUGLIST_VIEW where CUSTOMER_ID = :id )');             
        $req5 = $this->db->prepare('delete from EBSRD_EBSCUST where EBSCUST IN (select ID from EBSCUST where CUSTOMER = :id )');                
        $req6 = $this->db->prepare('delete from EBSCUST where CUSTOMER = :id');             
        $req7 = $this->db->prepare('delete from SC_SR where SUPPORTCENTER in (select ID from SUPPORTCENTER where customer = :id )');                
        $req8 = $this->db->prepare('delete from SUPPORTCENTER where customer = :id');               
        $req9 = $this->db->prepare('delete from EBSRD  where CUSTOMER = :id');              
        $req10 = $this->db->prepare('DELETE FROM CUSTOMER where id = :id');

        $req->bindParam(':id', $id, PDO::PARAM_INT);
        $req2->bindParam(':id', $id, PDO::PARAM_INT);
        $req3->bindParam(':id', $id, PDO::PARAM_INT);
        $req4->bindParam(':id', $id, PDO::PARAM_INT);
        $req5->bindParam(':id', $id, PDO::PARAM_INT);
        $req6->bindParam(':id', $id, PDO::PARAM_INT);
        $req7->bindParam(':id', $id, PDO::PARAM_INT);
        $req8->bindParam(':id', $id, PDO::PARAM_INT);
        $req9->bindParam(':id', $id, PDO::PARAM_INT);
        $req10->bindParam(':id', $id, PDO::PARAM_INT);

        $req->execute();
        $req2->execute();
        $req3->execute();
        $req4->execute();
        $req5->execute();
        $req6->execute();
        $req7->execute();
        $req8->execute();
        $req9->execute();
        $req10->execute();

    }

Ce n'est pas très beau et à l'exécution, c'est vraiment super long..
J'ai vu qu'il y avait mysqli_multi_query qui permettait de gérer celà, je ne sais pas si l'exécution serait plus rapide, mais en tout cas, je ne suis pas fan de mysqli..

Si vous avez des idées je suis prenneur ! :D