mysql - If statement in multiple SQL triggers -


i need mysql triggers, , guess should quite simple. have db consists of 3 tables (trable1, table2, table3), each of these has 2 columns (column1, column2). here need. if row inserted table1, want automaticaly replicated table2 , table3. likewise updates on table2 , table3. here trick, heed if condition, checks if row there, otherwise sql throws me error. grateful help.

do want throw error or want avoid it?

in first case, like

if exists (select 1 table2or3 col1 = new.col1)    signal ... end if; 

read more signals here.

if don't want throw error there's possibility

insert foo(col1, col2) values (new.col1, new.col2)  on duplicate key update whatever = whatever; 

if specify on duplicate key update, , row inserted cause duplicate value in unique index or primary key, update of old row performed.

read more here.

or

insert ignore .... 

if use ignore keyword, errors occur while executing insert statement treated warnings instead. example, without ignore, row duplicates existing unique index or primary key value in table causes duplicate-key error , statement aborted. ignore, row still not inserted, no error issued.

read more here.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -