I have 5 tables which are
Users
-id
-influencer_id
Influencers
-id
Categories
-catogory_id
-influencer_id
platforms
-influencer_id
-platform_id
tasks
-influencer_id
-task_id
I want to delete an influencer and also delete all records at once. How to do that?
use ON DELETE CASCADE while creating tables. Like:
CREATE TABLE child (
id INT,
parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id)
REFERENCES parent(id)
ON DELETE CASCADE
) ENGINE=INNODB;
http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html
First delete records from other tables. You can use following query:
DELETE FROM Users u
USING Influencers i
WHERE u.id = i.id;
You can do the same for other tables and then at last DROP
the Influencers
table.
DROP TABLE Influencers;