R
R
R4W2015-04-28 01:18:34
PHP
R4W, 2015-04-28 01:18:34

How to write mysql switch/case trigger correctly?

Good afternoon colleagues. The topic of triggers is quite new for me, but the task is urgent, so I ask for help with a ready-made code example. Algorithm is approximate such:
At insert'e in the table t1 to touch values ​​of the field t1.field1
if t1.field1 = value1 that we delete all line which was added.
if t1.field1 = value2 then update t2.field2 = t1.field2 and t2.field3 = t1.field3 where t2.id = t1.id
if t1.field1 = value3 then update t2.field2 = custom value where t2.id = t1.id
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Doomk, 2015-04-28
@Doomk

This article will help you

CASE [t1.field1 ]

   WHEN значение1 THEN DELETE t1 where t1.field1 = "значение1"
   WHEN значение2 THEN UPDATE t2.field2 = t1.field2 and t2.field3 = t1.field3 where t2.id = t1.id
   WHEN значение3 THEN UPDATE t2.field2 = кастомное значение где t2.id = t1.id 


END

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question