Mysql視圖, 存儲過程, 觸發器, 事務

1.觸發器
mysql> delimiter |
mysql> create trigger beforeinsertuserinfo
    -> before insert on userinfo
    -> for each row begin
    ->   insert into userinfolog values(now(),CONCAT(new.userid,new.username));
    -> end;
    -> |
mysql> delimiter ;
mysql> show triggers;
2.存儲過程
mysql> delimiter //
mysql> create procedure spinsertuserinfo(
    -> puserid int,pusername varchar(10)
    -> ,puserbirthday date
    -> )
    -> begin
    -> insert into userinfo values(puserid,pusername,puserbirthday);
    -> end;
    -> //
mysql> show procedure status like 'spinsertuserinfo';
mysql> call spinsertuserinfo(1,'zhangsan',current_date);
mysql> select * from userinfo;
3.自定義函數 mysql> update userinfo     -> set userbirthday='2000.01.01'     -> where userid='1'; mysql> drop function if exists fngetage; mysql> delimiter // mysql> create function fngetage(pbirthday date)     -> returns integer     -> begin     -> return year(now()) - year(pbirthday);     -> end     -> // 4.視圖 mysql> create view viewuserinfo     -> as select * ,fngetage(userbirthday) as userage from userinfo; mysql> select * from viewuserinfo; 清除日誌記錄 mysql> truncate table userinfolog; mysql> delete from userinfolog;
相關文章
相關標籤/搜索