怎么同时删除几个表?新手求指导
后台管理里根据ID删除一个表的相关的信息然后怎么删除其它几个表中相关ID的信息啊?急。。
------解决方案--------------------既然有 id 就继续删嘛
或者高级点:用触发器
------解决方案--------------------手册说:
通过在FOR EACH ROW之后使用BEGIN ... END复合语句结构,能够定义执行多条语句的触发程序。
------解决方案--------------------DELIMITER $$
create trigger xi_delete after delete
ON xinxi for each row
FOR EACH ROW
BEGIN
delete from us_xi where userid=old.userid,
delete from ccs_image where userid=old.userid,
delete from guestbook where userid=old.userid,
delete from friends where userid=old.userid;
END$$
DELIMITER;
------解决方案--------------------老大都说了“既然有 id 就继续删嘛”。
联表删!
------解决方案--------------------一般都是一个一个地删除。