当前位置:网站首页>Triggers in MySQL
Triggers in MySQL
2022-06-12 08:16:00 【Eldest brother Li dada】
Data preparation
create database if not exists mydb10_trigger;
use mydb10_trigger;
-- User table
create table user(
uid int primary key ,
username varchar(50) not null,
password varchar(50) not null
);
-- User information operation log table
create table user_logs(
id int primary key auto_increment,
time timestamp,
log_text varchar(255)
);
1. When user Add a row of data to the table , stay user_log Add logging to
-- Defining triggers :
create TRIGGER trigger_test1 after insert
on user for each row
insert into user_logs values(NULL,now(),' New users added ');
insert into user values(1,' Zhang San ','123456');
2. When user Add a row to the table to modify , stay user_log Add logging to
-- Defining triggers :
delimiter $$
create TRIGGER trigger_test3 before update
on user for each row
begin
insert into user_logs values(NULL,now(),' Modified by new users ');
end $$
delimiter;
-- modify user Data in
update user set password = '8888'where uid = 1;
-- NEW
create TRIGGER trigger_test4 after insert
on user for each row
insert into user_logs values(NULL,now(),concat(' New users added , The message is :',NEW.uid,NEW.username,NEW.password));
insert into user values(2,' Li Si ','123456');
update Type of trigger
-- OLD
create TRIGGER trigger_test5 after update
on user for each row
insert into user_logs values(NULL,now(),concat(' Modified by new users , The message is :',OLD.uid,OLD.username,OLD.password));
update user set password = '88888'where uid = 2;
-- new
create TRIGGER trigger_test4 after insert
on user for each row
insert into user_logs values(NULL,now(),concat(' New users added , The message is :',NEW.uid,NEW.username,NEW.password));
delete Type of trigger
create TRIGGER trigger_test4 after delete
on user for each row
insert into user_logs values(NULL,now(),concat(' Some users have been deleted , The message is :',OLD.uid,OLD.username,OLD.password));
Delete trigger :
drop trigger if exists trigger_test1;
边栏推荐
- Map the world according to the data of each country (take the global epidemic as an example)
- Principes et exemples de tâches OpenMP
- 2.1 linked list - remove linked list elements (leetcode 203)
- 模型压缩 | TIP 2022 - 蒸馏位置自适应:Spot-adaptive Knowledge Distillation
- Debug debugging cmake code under clion, including debugging process under ROS environment
- Alibaba cloud deploys VMware and reports an error
- 对企业来讲,MES设备管理究竟有何妙处?
- (P21-P24)统一的数据初始化方式:列表初始化、使用初始化列表初始化非聚合类型的对象、initializer_lisy模板类的使用
- Derivation of Poisson distribution
- Hands on deep learning -- activation function and code implementation of multi-layer perceptron
猜你喜欢

Vision Transformer | CVPR 2022 - Vision Transformer with Deformable Attention

Hands on deep learning 18 -- model selection + over fitting and under fitting and code implementation

Model compression | tip 2022 - Distillation position adaptation: spot adaptive knowledge distillation

APS究竟是什么系统呢?看完文章你就知道了

How to write simple music program with MATLAB

企业为什么要实施MES?具体操作流程有哪些?

(P36-P39)右值和右值引用、右值引用的作用以及使用、未定引用类型的推导、右值引用的传递

Instructions spéciales pour l'utilisation du mode nat dans les machines virtuelles VM

Hands on deep learning -- concise implementation code of weight decay

ctfshow web4
随机推荐
Uni app screenshot with canvas and share friends
工厂的生产效益,MES系统如何提供?
Clarify the division of IPv4 addresses
vm虚拟机中使用NAT模式特别说明
EasyExcel导出Excel表格到浏览器,并通过Postman测试导出Excel【入门案例】
. net mysql Too many connections
Discrete chapter I
Hands on learning and deep learning -- simple implementation of softmax regression
MES系统是什么?MES系统的操作流程是怎样?
Installation series of ROS system (I): installation steps
HDLC protocol
Map the world according to the data of each country (take the global epidemic as an example)
(p36-p39) right value and right value reference, role and use of right value reference, derivation of undetermined reference type, and transfer of right value reference
Pytorch practice: predicting article reading based on pytorch
js中的正则表达式
2.2 linked list - Design linked list (leetcode 707)
StrVec类 移动拷贝
System service configuration service - detailed version
MYSQL中的触发器
Upgrade eigen to version 3.3.5 under Ubuntu 16.04