- 浏览: 768327 次
- 性别:
- 来自: 上海
-
文章分类
- 全部博客 (573)
- Java基础 (76)
- C++基础 (5)
- hibernate (5)
- struts (4)
- spring (1)
- webservice (7)
- AjaX基础 (0)
- JS脚本 (53)
- 正则表达式 (5)
- html脚本 (30)
- 数据库基础 (54)
- 工作相关 (49)
- 其他 (30)
- Linux (9)
- web服务器 (17)
- JSP (13)
- eclipse (6)
- 面试题相关 (20)
- XML (3)
- Apache common (2)
- 生活 (35)
- VMware (1)
- log4j (9)
- BeanUtils (2)
- 设计模式 (3)
- UML (1)
- UNIX (1)
- ibats (5)
- GT-Grid (17)
- ABAP学习 (17)
- ABAP (35)
- ABAP--ALV (11)
- ABAP--WEBDIMPRO (0)
- abap-sample (1)
- BEMS (2)
- flex (33)
- GIS技术 (3)
最新评论
触发器能进行一些约束.
这是个小例子,当Student表的StudentID列被发生更改时,BorrowStudent表的StudentID列也跟着更改.如果Student表删除某记录,BorrowStudent也删除对应StudentID的记录.
/*先删除将要创建而存在的表*/
drop table if exists Student;
drop table if exists BorrowStudent;
/*创建表*/
create table Student(
StudentID int not null primary key,
StudentName varchar(30) not null,
StudentSex enum('m','f') default 'm'
)engine=myisam;
create table BorrowStudent(
BorrowRecord int not null auto_increment primary key,
StudentID int not null,
BorrorDate date,
ReturnDate date,
foreign key(StudentID) references Student(StudentID)
)engine=myisam;
/*插入记录*/
insert into Student values(1235412,'java','m');
insert into Student values(3214562,'jiajia','m');
insert into Student values(5441253,'purana','f');
insert into BorrowStudent(StudentID,BorrorDate,ReturnDate)
values(1235412,'2007-01-01','2007-01-07');
insert into BorrowStudent(StudentID,BorrorDate,ReturnDate)
values(3214562,'2007-01-01','2007-01-07');
insert into BorrowStudent(StudentID,BorrorDate,ReturnDate)
values(5441253,'2007-01-01','2007-01-07');
/*创建触发器*/
delimiter $$
drop trigger if exists tduStudent$$
drop trigger if exists tddStudent$$
create trigger tduStudent before update
on Student for each row
begin
if new.StudentID!=old.StudentID then
update BorrowStudent
set BorrowStudent.StudentID=new.StudentID
where BorrowStudent.StudentID=old.StudentID;
end if;
end$$
create trigger tddStudent before delete
on Student for each row
begin
delete
from BorrowStudent
where BorrowStudent.StudentID=old.StudentID;
end$$
delimiter ;
这是个小例子,当Student表的StudentID列被发生更改时,BorrowStudent表的StudentID列也跟着更改.如果Student表删除某记录,BorrowStudent也删除对应StudentID的记录.
/*先删除将要创建而存在的表*/
drop table if exists Student;
drop table if exists BorrowStudent;
/*创建表*/
create table Student(
StudentID int not null primary key,
StudentName varchar(30) not null,
StudentSex enum('m','f') default 'm'
)engine=myisam;
create table BorrowStudent(
BorrowRecord int not null auto_increment primary key,
StudentID int not null,
BorrorDate date,
ReturnDate date,
foreign key(StudentID) references Student(StudentID)
)engine=myisam;
/*插入记录*/
insert into Student values(1235412,'java','m');
insert into Student values(3214562,'jiajia','m');
insert into Student values(5441253,'purana','f');
insert into BorrowStudent(StudentID,BorrorDate,ReturnDate)
values(1235412,'2007-01-01','2007-01-07');
insert into BorrowStudent(StudentID,BorrorDate,ReturnDate)
values(3214562,'2007-01-01','2007-01-07');
insert into BorrowStudent(StudentID,BorrorDate,ReturnDate)
values(5441253,'2007-01-01','2007-01-07');
/*创建触发器*/
delimiter $$
drop trigger if exists tduStudent$$
drop trigger if exists tddStudent$$
create trigger tduStudent before update
on Student for each row
begin
if new.StudentID!=old.StudentID then
update BorrowStudent
set BorrowStudent.StudentID=new.StudentID
where BorrowStudent.StudentID=old.StudentID;
end if;
end$$
create trigger tddStudent before delete
on Student for each row
begin
delete
from BorrowStudent
where BorrowStudent.StudentID=old.StudentID;
end$$
delimiter ;
发表评论
-
oracle获取指定的日期、时间
2012-07-17 14:32 1036--本周 select trunc(sysdate, 'd ... -
Oracle 常用日期提取脚本汇总
2012-07-17 14:30 775Oracle 常用日期提取脚本汇总 1、本周第一天和最后一 ... -
Windows下安装PostgreSQL8.2图解
2010-08-20 13:16 1121Windows下安装PostgreSQL8.2图解 -
关于用户角色权限管理一点想法
2010-06-09 10:46 1045关键字: 权限 --------------------- ... -
sql语句解析顺序
2010-05-20 14:47 1325标准的 SQL 的解析顺序 ... -
postgreSql 利用触发器创建动态表
2010-05-20 14:43 1674在postgresql 中如果在程序运行中需要根据插入数据条件 ... -
使用反射实现ORM
2010-01-14 22:09 887首先Bean在符合JavaBean的要求,即有一个无参的构造方 ... -
模板设计模式_构建公共通用的Dao
2010-01-14 22:04 906核心代码: Connection的工具类:详见:JDBC数据 ... -
使用构造函数创建JavaScript对象
2010-01-14 21:31 906<!DOCTYPE html PUBLIC " ... -
数据库行转列
2010-01-14 21:09 775create table score ( s_id int ... -
SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
2010-01-14 20:56 873Insert是T-sql中常用语句,Insert INTO t ... -
mysql导入导出
2010-01-12 12:05 14331. 导出 view plaincopy to clip ... -
mysql导入与导出和删除多条数据数据
2010-01-12 11:57 2193数据导出: mysql> select * from ... -
MySQL索引分类和各自用途
2010-01-12 11:43 1449一、 MySQL: 索引以B树格 ... -
各种主流数据库的分页写法
2010-01-11 16:38 617------------------------------- ... -
MySQL中进行树状所有子节点的查询
2010-01-06 21:16 1192在Oracle 中我们知道有一个 Hierarchical Q ... -
MySQL中进行树状所有子节点的查询
2009-12-29 14:52 977在Oracle 中我们知道有一个 Hierarchical Q ... -
超详细的SQL语句语法
2009-12-28 18:08 986简单的Transact-SQL查询只包括选择列表、FROM子句 ... -
有关SQL模糊查询
2009-12-28 12:50 1174执行 数据库查询时,有 ... -
视图,存储过程,触发器的好处
2009-12-23 11:33 1022视图的优点: 提高数据安全性,可以不让用户看到表中的某个字 ...
相关推荐
主要介绍了mysql触发器之触发器的增删改查操作,结合实例形式分析了mysql触发器的定义及使用触发器进行增删改查等相关操作技巧,需要的朋友可以参考下
本文实例讲述了mysql触发器之创建多个触发器操作。分享给大家供大家参考,具体如下: 这次记录的内容mysql 版本必须得是5.7.2+的哈,之前的会不好使的。废话不多说,咱们开始正文哈。 在mysql 5.7.2+版本之前,我们...
mysql触发器使用mysql触发器使用mysql触发器使用mysql触发器使用mysql触发器使用mysql触发器使用mysql触发器使用mysql触发器使用mysql触发器使用mysql触发器使用mysql触发器使用mysql触发器使用mysql触发器使用mysql...
mysql触发器+存储过程
MySQL触发器教程
MYSQL触发器,可以使用它用来进行监控,例如商品价格变化,下单后商品库存减少等实用性操作!
MYSQL触发器在PHP项目中用来做信息备份、恢复和清空 MYSQL触发器在PHP项目中用来做信息备份、恢复和清空
我们已经去掉了关于触发器的错误的语句,但是仍旧有很多旧版本的手册在网上,举个例子,这是一个德国的Url上的: http://dev.mysql.com/doc/mysql/de/ANSI_diff_Triggers.html. 这个手册上说触发器就是存储过程,...
MySQL触发器
MySQL触发器说明和编写时的注意事项,其功能越来越强,可以学习
mysql触发器教程
本文实例讲述了mysql触发器之创建使用触发器。分享给大家供大家参考,具体如下: 我们可以可以使用CREATE TRIGGER语句创建一个新的触发器,来看下具体的语法: CREATE TRIGGER trigger_name trigger_time trigger_...
MySQL触发器深入解析 在MySQL数据库中,触发器是一种特殊类型的存储程序,它能够在某个表上发生特定事件(如INSERT、UPDATE或DELETE)时自动执行。触发器为数据库提供了一种在数据变更时自动执行特定操作的机制,...
mysql触发器
MySQL触发器、存储过程、自定义函数、视图简单示例
MYSQL触发器与存储过程.ppt
"MySQL触发器在电子商城系统中的应用" MySQL触发器是一种特殊的存储过程,主要通过事件触发从而执行。通过订单与库存管理的案例,详细阐述了触发器的特性及在电子商城系统中的应用。 触发器的主要应用场合有:当向...
mysql触发器使用实例 看下例子基本上就会操作了!