drop trigger if exists `trig_update_stat_book_ins`;
DELIMITER ##
create trigger `trig_update_stat_book_ins` 
    after insert on book 
    for each row begin
    update user_stat set user_bookcount=user_bookcount+1 where user_stat.user_id=NEW.user_id;
end ##
DELIMITER ;

drop trigger if exists `trig_update_stat_book_del`;
DELIMITER ##
create trigger `trig_update_stat_book_del` 
    after delete on book 
    for each row begin
    update user_stat set user_bookcount=user_bookcount-1 where user_stat.user_id=OLD.user_id;
end ##
DELIMITER ;

drop trigger if exists `trig_update_stat_doc_ins`;
DELIMITER ##
create trigger `trig_update_stat_doc_ins` 
    after insert on document 
    for each row begin
    update user_stat set user_doccount=user_doccount+1 where user_stat.user_id=NEW.user_id;
    update user_stat set user_usedspace=user_usedspace+NEW.doc_size where user_stat.user_id=NEW.user_id;
end ##
DELIMITER ;

drop trigger if exists `trig_update_stat_doc_del`;
DELIMITER ##
create trigger `trig_update_stat_doc_del` 
    after delete on document 
    for each row begin
    update user_stat set user_doccount=user_doccount-1 where user_stat.user_id=OLD.user_id;
    update user_stat set user_usedspace=user_usedspace-OLD.doc_size where user_stat.user_id=OLD.user_id;
end ##
DELIMITER ;

drop trigger if exists `trig_update_stat_type_ins`;
DELIMITER ##
create trigger `trig_update_stat_type_ins` 
    after insert on typetable
    for each row begin
    update user_stat set user_typecount=user_typecount+1 where user_stat.user_id=NEW.user_id;
end ##
DELIMITER ;

drop trigger if exists `trig_update_stat_type_del`;
DELIMITER ##
create trigger `trig_update_stat_type_del` 
    after delete on typetable
    for each row begin
    update user_stat set user_typecount=user_typecount-1 where user_stat.user_id=OLD.user_id;
end ##
DELIMITER ;