Jump to content
php.lv forumi

dzēst visus ierakstus ar noteiktu lauka vērtību


yeahz

Recommended Posts

Ir tabulas ar šādu struktūru:

 

table1
+----+------------+---------+
| id | article_id | kautkas |
+----+------------+---------+

table2
+----+------------+---------+
| id | article_id | kautkas |
+----+------------+---------+

table3
+----+------------+---------+
| id | article_id | kautkas |
+----+------------+---------+

 

Vai var izdzēst no visas datubāzes, kur ir, piemēram, article_id=6? Vajag šo izmantot pie raksta dzēšanas un lai visi raksta dati arī tiek izdzēsti no datubāzes, savādāk jātaisa katrai tabulai savs kverijs + ja izveido kaut ko jaunu (pluginu, addonu), tad par šo var piemirst (izveidot vēl kveriju dzēšanai jaunajam addonam).

Edited by yeahz
Link to comment
Share on other sites

imo uz MyISAM neies tas FOREIGN KEY, laikam būs jālieto innodb

Dokumentācijā šitādu atradu, kā CASCADE DELETE aizvietotājs laikam der:

CREATE TRIGGER delete_myisam_child
 BEFORE DELETE
 ON myisam_parent
 FOR EACH ROW
 BEGIN
   DELETE FROM myisam_child WHERE mparent_id=old.mparent_id;
 END;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...