I have a PARENT table and a CHILD table.
PARENT
------
ID BIGINT PRIMARY KEY
NAME VARCHAR(255) NOT NULL
CHILD
-----
ID BIGINT PRIMARY KEY
NAME VARCHAR(255) NOT NULL
PARENT_ID BIGINT NOT NULL
I want to create a trigger which does
- when a CHILD row inserted or updated
- check the NEW.NAME
- and if the NEW.NAME is NULL or EMPTY
- use PARENT's NAME as NEW.NAME
How can I do that?
Best Answer
Tables:
Trigger:
Test:
There's no error checking etc, but I'll leave that as an exercise for you.