触发器 随写
来源:互联网 发布:天下3萝莉捏脸数据 编辑:程序博客网 时间:2024/05/20 09:47
列子:
create table testproc if not exists (
`i_id` int(11) primary key,
`i_name` varchar(30) character set utf8 not null,
`url` varchar(40) character set utf8 not null
)engine=myisam default charset=utf8;
create table tree_test if not exists(
`form_id` int(11) not null,
`parent_form_id` int(11) not null
)engine=myisam default charset=utf8;
drop trigger if exists pseudohash_crc_ins;
create trigger pseudohash_crc_ins before insert on testproc for each row
begin set @x = "hello trigger";
set NEW.i_name=crc32(NEW.url);
set new.url=@f;
end;
drop trigger if exists pseudohash_crc_upd;
create trigger pseudohash_crc_upd before update on testproc for each row
begin set @x = "hello trigger";
update tree_test set parent_form_id=crc32(NEW.url)where form_id=new.i_id;
end;
前提是 必须有这两张表 tree_test,testproc
before insert :是说 在往自己表里插入一条数据之前 需要做的事情,这里的逻辑是 插入之前 现在要插入的 url字段参数 用crc32 转成一串数字 然后再赋值给当前要插入的i_name字段,如果你插入值 写了 i_name 参数,那么这儿会把你写的那个参数值覆盖掉。
new : 是代表 你当前将要修改的 或者插入的 一条数据
old: 是代表 之前最后一次 修改过的 或者插入过的数据
before update: 修改之前
after update : 修改之后
不知道 存储过程 和函数 能不能和触发器 在一块用,因为有的文章说“ 触发程序不能调用将数据返回客户端的存储程序,也不能使用采用CALL语句的动态SQL
(允许存储程序通过参数将数据返回触发程序)”,没太看懂,没测试。
如下有个截图:
优缺点:
- 触发器 随写
- 跨服务器写触发器
- Oracle写的触发器
- 再写一点数据库触发器
- MySQL写触发器,级联删除
- 自己写的第一个SQLSERVER2005触发器
- 我写的sybase触发器,学习下
- ORA-04091:触发器写错了
- mysql中写存储过程,试图,触发器
- sql触发器语句的构写
- 创建一个可以写本地文件的触发器
- 最近写的触发器,保存一下
- 第一次写oracle触发器,记录一下
- oracle如何写一个触发器及序列号
- 触发器
- 触发器
- 触发器
- 触发器
- C语言经典算法100例-072-创建一个链表
- Linux下gcc与g++用法以及编写makefile
- Thirft框架介绍
- 女人与大数据[转]
- 文章、留言系统的开发
- 触发器 随写
- mfc中静态文本框修改
- Ubuntu下解压tar软件包的方法
- 使用MT快速搭建移动端webapp
- Build path entry is missing:org.eclipse.jdt.launching.JRE_CONTAINER/
- 解决JAVA Applet被本地安全设置阻止问题
- ActivMQ中文文档
- c语言的sqlite3接口的设计
- jeecms3.0.4版本 详解请求如何找到首页