-- Active: 1714203732007@@127.0.0.1@3306@db_trigger
create table student(
id int unsigned auto_increment primary key not null,
name varchar(50)
);
--1次添加
insert into student(name) values('jack');
--2次添加
insert into student(name) values('Tom');
create table student_total(total int);
insert into student_total values(1);
delimiter $$
create trigger student_insert_trigger after insert
on student for each row
BEGIN
update student_total set total=total+1;
# 其他SQL
END
$$
SQL语句意思为:每次为student添加一条数据,student_total内值加1。
第一次:
第二次:
student_total内的值成功加1。