开发者

MySQL triggered delete

开发者 https://www.devze.com 2023-01-12 09:43 出处:网络
I have 2 tables: User (id, user, pass, ...) Post (user_id, post, ...) I would开发者_C百科 like to create a trigger which delete post of a user, before deleting user... Can you help me?if the table

I have 2 tables:

User (id, user, pass, ...)

Post (user_id, post, ...)

I would开发者_C百科 like to create a trigger which delete post of a user, before deleting user... Can you help me?


if the tables is innodb engine

you can use

ON DELETE CASCADE 

http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

look an example here :

MySQL foreign key constraints, cascade delete


Use a stored procedure

0

精彩评论

暂无评论...
验证码 换一张
取 消