有两个表 一个为temp 一个为 date 我想要在temp中按id删除一条记录时把 这条记录插入到date表中 在Navicat Lite中定义触发器 希望大虾指教一下不胜感激 在线等
解决方案 »
- 刚准备学Mysql,求助高手.
- 怎么样让带有auto_increment属性的id列中一些记录被删除之后,后面的id自动把前面的填充满呢?
- 聚合问题
- 请教explain中extra using where问题
- 求一个存储过程写法
- 这个where子句有错误,SQL无法运行。
- java.sql.SQLException: Unknown type '246 in column 0 of 1 in binary-encoded result set.
- 关于MY-SQL管理员密码的问题,100分急求!!!在线等待!!!
- mysql安装问题
- 求指点:如何连接两个表作股票价格的收益率计算?
- N多人都没搞定的SQL语句
- mysql Navicat Lite触发器
-> id int primary key,
-> col int
-> );
Query OK, 0 rows affected (0.27 sec)mysql> create table `date`
-> (
-> id int,
-> col int
-> );
Query OK, 0 rows affected (0.13 sec)mysql> delimiter //
mysql>
mysql> create trigger trg_temp_bd before delete ON `temp`
-> FOR EACH ROW BEGIN
-> INSERT INTO `date` values(old.id,old.col);
-> END;
->
-> //
Query OK, 0 rows affected (0.11 sec)mysql> delimiter ;
mysql> insert into `temp` values
-> (1,100),
-> (2,200),
-> (3,300),
-> (4,400);
Query OK, 4 rows affected (0.16 sec)
Records: 4 Duplicates: 0 Warnings: 0mysql> select * from `temp` ;
+----+------+
| id | col |
+----+------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
| 4 | 400 |
+----+------+
4 rows in set (0.00 sec)mysql> select * from `date`;
Empty set (0.03 sec)mysql>
mysql> delete from `temp` where id=2 or id=3;
Query OK, 2 rows affected (0.11 sec)mysql> select * from `temp` ;
+----+------+
| id | col |
+----+------+
| 1 | 100 |
| 4 | 400 |
+----+------+
2 rows in set (0.00 sec)mysql> select * from `date`;
+------+------+
| id | col |
+------+------+
| 2 | 200 |
| 3 | 300 |
+------+------+
2 rows in set (0.00 sec)mysql>