标签:
触发器
mysql> DELIMITER //
mysql> CREATE TRIGGER newproduct AFTER INSERT ON products
-> FOR EACH ROW
-> SELECT ‘added ‘ INTO @ee;
-> //
Query OK, 0 rows affected (0.05 sec)
mysql> insert into products (prod_id, vend_id, prod_name, prod_price, prod_desc)
-> values
-> (‘TNT3‘, 1002, ‘liwei‘, 123.12, ‘dudu jiushi ni‘)
-> //
Query OK, 1 row affected (0.03 sec)
select @ee
//
+------+
| @ee |
+------+
| added |
+------+
DROP TRIGGER newproduct
mysql> create trigger neworder after insert on orders
-> for each row select new.order_num into @liwei;
mysql> insert into orders(order_date,cust_id)
-> values (Now(), 10001);
mysql> select @liwei;
+--------+
| @liwei |
+--------+
| 20010 |
+--------+
1 row in set (0.02 sec)
mysql> create trigger deleteorder before delete on orders
-> for each row select old.order_num,old.order_date into @liwei,@tx;
mysql> delete from orders where order_num = 10002;
Query OK, 1 row affected (0.14 sec)
mysql> select @liwei;
+--------+
| @liwei |
+--------+
| 10002 |
+--------+
create trigger deleteorder before delete on orders
for each row
begin
insert into otherorder (order_num, prder, cust_id)
values
( old.order_num, old.order_date, old.cust_id);
mysql> create trigger upvendor before update on vendors
-> for each row set new.vend_state = upper(new.vend_state);
Query OK, 0 rows affected (0.21 sec)
CREATE TRIGGER tr1
BEFORE UPDATE ON liwei
FOR EACH ROW
BEGIN
SET @old = OLD.s1;
SET @new = NEW.s1;
END;
not allowed to return a result set from a trigger
标签:
原文地址:http://www.cnblogs.com/duhuo/p/4655957.html