网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

MySQL创建触发器

时间:2024-11-03 02:22:10

1、首先创建一个数倌栗受绽据表,内容如图mysql> create table tb_emp8 -> ( -> id int(11)primary key not null, -> name varchar(22) unique, -> depId int(11) not null, -> salary float default 0);Query OK, 0 rows affected (0.01 sec)

MySQL创建触发器

3、创建一个名为 SumOfSalary 的触发器,触发的条件是向数据表 tb_emp8 中插入数据之前,对新插入的 salary 字段值进行求和计算。输入的 SQL 语句和执行过程如下所示。

MySQL创建触发器

5、然后往里面插入数据,sum会自动增加mysql> INSERT INTO tb_emp8 -> VALUES(3,'c',1,1000),(4,'d',1,500);Query OK, 2 rows affected (0.00 sec)Records: 2 Duplicates: 0 Warnings: 0

MySQL创建触发器
© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com