Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL Triggers #306

Open
uniquejava opened this issue May 1, 2020 · 0 comments
Open

MySQL Triggers #306

uniquejava opened this issue May 1, 2020 · 0 comments

Comments

@uniquejava
Copy link
Owner

uniquejava commented May 1, 2020

Introduction to MySQL AFTER UPDATE triggers

不能像oracle那样

unfortunately we can't use in MySQL after INSERT or UPDATE description, like in Oracle

MySQL Fire Trigger for both Insert and Update

cyper 实战

# drop trigger ON_GRADE_UPDATE;
create trigger ON_GRADE_UPDATE
    after update
    on customer
    for each row

begin
    if old.grade <> new.grade THEN
        insert into event(event_title, event_description, start_date, end_date, start_time, end_time,
                          is_full_day_event,
                          is_recurring, created_by,
                          created_at, parent_event_id)
        values ('customer grade changed!', concat('from ', old.grade, ' to ', new.grade), now(), null,
                null, null, 'N', 'N', 'cyper', now(), null);
    end if;

end;

drop trigger if exists comment_count_changes;
create trigger comment_count_changes
    after insert
    on cms_comment
    for each row
begin
    select t.created_by, t.title into @author, @title from cms_post t where id = new.post_id;

    if @author = 2 then
        insert into event(event_title, event_description, start_date, end_date, start_time, end_time,
                          is_full_day_event,
                          is_recurring, created_by,
                          created_at, parent_event_id)
        values (@title, concat('刚有人回复了你的帖子:', new.body), now(), null,
                null, null, 'N', 'N', 'cyper', now(), null);
    end if;

end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant