MySQL创建触发器(简略版)
来源:互联网 发布:微信淘宝客自动发单 编辑:程序博客网 时间:2024/06/06 18:10
当删除某表的某数据的时候,自动触发触发器,删除特点指定表的数据
例如
删除后触发
CREATE TRIGGER Trigger_delete
after delete on goodcritic
for EACH ROW
BEGIN
SELECT good into @good from publishcritic where id=old.pid;
update publishcritic set good=@good-1 where id=old.pid;
end
插入的时候触发
CREATE TRIGGER Trigger_insert
AFTER INSERT on goodcritic
for each ROW
BEGIN
SELECT good into @good from publishcritic where id=new.pid;
update publishcritic set good=@good+1 where id=new.pid;
end
更新的时候触发
CREATE TRIGGER goodTrigger_insert
AFTER INSERT on goodcritic
for each ROW
BEGIN
UPDATE cc
SET good=good+(new.good-old.good)
WHERE id=new.id;
end备注:
Trigger_delete表示触发器的名字
after表示触发后执行,如果为before的话,则是触发前执行
delete表示 删除操作,对应还有update,insert操作
for each row表示对应所有行都会触发该触发器
如果是delete操作的话,则为old,如果为insert,则为new ,update的话,对应old和new
@good为声明一个变量,和sqlserver不一样,不需要声明其类型模版
create trigger 触发器名字
after/before delete/update/insert on 表的名字
for each row
begin
SQL 语句
end
- MySQL创建触发器(简略版)
- mysql创建触发器
- mysql创建触发器
- mysql 创建触发器
- mysql创建简单触发器
- naavicat 创建MySQL触发器
- mysql创建触发器
- mysql创建触发器
- MySQL 下创建触发器
- 创建mySQL触发器
- mysql创建触发器
- mysql创建触发器
- mysql 创建触发器 记录
- MySql-创建触发器
- 基于xml创建Java用户界面(简略版)
- 关于mysql中创建触发器
- mysql创建触发器报错
- java程序创建mysql触发器
- 【NOIp模拟】【二分图or并查集】GoToandPlay
- Android studio如何利用Android.mk编译生成多个so文件
- mysql语句
- 深入uCOS中全局变量的使用详解
- AOJ.800 热身之开关灯
- MySQL创建触发器(简略版)
- Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication
- php数组去重
- java获取项目中文件路径
- 使用DatePicker以及TimePicker显示当前日期和时间
- Xcode8的assets问题导致运行iOS8崩溃的解决方案
- 【Android】史上最简单,一步集成侧滑(删除)菜单,高仿QQ、IOS。
- RxJava开发精要
- spring boot在Eclipse中,修改代码后无需重启就生效的配置