Question:
How to delete rows from multiple Tables?
Andulien
2012-08-30 04:26:38 UTC
Basically I want to build a query to delete all user information from multiple tables.
I got one table where the memberid is. One table with a petid (a member can have multiple pets). Serveral other tables that either utilize the petid or the memberid. Is there a way to cover this in one script or will I have to split this up? Thanks for the help.
Three answers:
?
2012-08-30 04:43:58 UTC
you can process many deletes when a php page is run.. just do something like...



$delete1 = mysql_query("DELETE FROM table1 WHERE memberid='$memberid'")

or die(mysql_error());



$delete2 = mysql_query("DELETE FROM table2 WHERE memberid='$memberid'")

or die(mysql_error());



when the php file is run it will delete from table 1 then it will delete from table 2
Ratchetr
2012-08-30 04:51:29 UTC
Most databases support cascade delete. You need to specify this when you create the foreign key constraints in your tables. If ON DELETE CASCADE is specified as part of the foreign key constraint, then deleting a row from the parent table will delete all rows referencing it in the child table.



In MySQL you need to use the InnoDB enging for ON DELETE CASCADE to work.



First link gives a simple example in the answer. Second link is MySQL documentation. If using other database, just Google it to find the exact syntax.
marchinkoski
2016-12-10 11:19:13 UTC
it somewhat is a flow-internet site scripting vulnerability. It shows an sq. server it somewhat is the two not set up appropriate and/or does not have each and every of the Microsoft risk-free practices updates utilized. until you get the risk-free practices matters fastened, do not difficulty cleansing it, it gets re-contaminated. that's the comparable form of hack that those days made the information with Obama's internet internet site being hacked.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...