0

I have 2 tables:

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

Post (user_id, post, ...)

I would like to create a trigger which delete post of a user, before deleting user... Can you help me?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Wolfy
  • 4,213
  • 8
  • 35
  • 42

2 Answers2

0

Use a stored procedure

polemon
  • 4,722
  • 3
  • 37
  • 48
0

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

Community
  • 1
  • 1
Haim Evgi
  • 123,187
  • 45
  • 217
  • 223