-- 用户表添加语句添加触发器,要求在添加用户信息时初始化用户钱包表数据,初始金额为0
DELIMITER $$ -- 更改默认语句分隔符为$$,这样可以在触发器内部使用;
CREATE TRIGGER AFTER_user_INSERT
AFTER INSERT ON user
FOR EACH ROW
BEGIN
INSERT INTO user_wallet(user_id,balance)
VALUES(new.user_id,0.00);
END;
$$
DELIMITER;
INSERT INTO user(username,password,email,phone)
VALUES('张三','123456','88888888@qq.com','13788888888');
CREATE TRIGGER user_delete_trigger
BEFORE DELETE ON `user`
FOR EACH ROW
BEGIN
DELETE FROM user_wallet WHERE user_id=old_user_id;
DELETE FROM user_wallet_log WHERE user_id=old.user_id;
END;
$$
DELIMITER;
DELETE FROM `user` WHERE user_id =4;