首页 小组 文章 相册 留言本 用户 搜索 我的社区 在线学堂 商城 购物车 支付钱包

[打卡]6.20 万物不及桐神

2024-06-20 10:08:19
0
308

-- 用户表添加语句添加触发器,要求在添加用户信息时初始化用户钱包表数据,初始金额为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;

评论
意见反馈