当前位置:网站首页>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;
边栏推荐
- Summary of structured slam ideas and research process
- You get download the installation and use of artifact
- Easyexcel exports excel tables to the browser, and exports excel through postman test [introductory case]
- call方法和apply方法
- Xiaomi mobile phone recording data set software operation
- In depth interpretation of 5g key technologies
- Ten important properties of determinant
- 千万别把MES只当做工具,不然会错过最重要的东西
- A brief summary of C language printf output integer formatter
- MYSQL中的触发器
猜你喜欢

电气火灾探测器对各用电回路进行实时监控

Py&GO编程技巧篇:逻辑控制避免if else

Hands on deep learning -- weight decay and code implementation

You get download the installation and use of artifact

How to write simple music program with MATLAB

网站Colab与Kaggle

Figure neural network makes Google maps more intelligent

Clarify the division of IPv4 addresses

Hands on deep learning -- activation function and code implementation of multi-layer perceptron

Model Trick | CVPR 2022 Oral - Stochastic Backpropagation A Memory Efficient Strategy
随机推荐
MES系统质量追溯功能,到底在追什么?
js中的正则表达式
802.11 protocol: wireless LAN protocol
ctfshow web3
tmux常用命令
Cookies and sessions
Talk about the four basic concepts of database system
Procedure execution failed 1449 exception
对企业来讲,MES设备管理究竟有何妙处?
Vision transformer | arXiv 2205 - TRT vit vision transformer for tensorrt
DUF:Deep Video Super-Resolution Network Using Dynamic Upsampling Filters ...阅读笔记
C # push box
Summary of structured slam ideas and research process
Data visualization and Matplotlib
Vision transformer | arXiv 2205 - TRT vit vision transformer for tensorrt
MYSQL中的调用存储过程,变量的定义,
Leetcode notes: Weekly contest 280
ctfshow web4
Hands on deep learning -- discarding method and its code implementation
MYSQL中的查询