av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

MySQL觸發(fā)器,存儲(chǔ)過程實(shí)例演示

以下的文章主要是介紹MySQL 觸發(fā)器,存儲(chǔ)過程以及函數(shù)與視圖的實(shí)例演示過程,以下就是觸發(fā)器,存儲(chǔ)過程以及函數(shù)與視圖的具體操作方案的描述,希望在你今后的學(xué)習(xí)中會(huì)對你有所幫助。

MySQL 觸發(fā)器,存儲(chǔ)過程以及函數(shù)與視圖的實(shí)例演示:

0.test數(shù)據(jù)庫有userinfo用戶信息表 和userinfolog用戶信息日志表

1.建立一個(gè)userinfo表新增記錄時(shí)的MySQL 觸發(fā)器 將新增日志加入到userinfolog

2.建立一個(gè)向userinfo表新增記錄的存儲(chǔ)過程

3.根據(jù)userinfo表的出生日期字段 我們將建立一個(gè)簡單算得年齡的自定義函數(shù)

4.創(chuàng)建一個(gè)userinfo的視圖 調(diào)用年齡函數(shù)

0.準(zhǔn)備相關(guān)表

 
 
 
  1. MySQL> use test;  
  2. MySQL> create table userinfo(userid int,username varchar(10),userbirthday date);  
  3. MySQL> create table userinfolog(logtime datetime,loginfo varchar(100));  
  4. MySQL> describe userinfo; 

1.MySQL 觸發(fā)器

 
 
 
  1. MySQL> delimiter |  
  2. MySQL> create trigger beforeinsertuserinfo  
  3. -> before insert on userinfo  
  4. -> for each row begin  
  5. -> insert into userinfolog values(now(),CONCAT(new.userid,new.username));  
  6. -> end;  
  7. -> |  
  8. MySQL> delimiter ;  
  9. MySQL> show triggers; 

2.存儲(chǔ)過程

 
 
 
  1. MySQL> delimiter //  
  2. MySQL> create procedure spinsertuserinfo(  
  3. -> puserid int,pusername varchar(10)  
  4. -> ,puserbirthday date  
  5. -> )  
  6. -> begin  
  7. -> insert into userinfo values(puserid,pusername,puserbirthday);  
  8. -> end;  
  9. -> //  
  10. MySQL> show procedure status like 'spinsertuserinfo';  
  11. MySQL> call spinsertuserinfo(1,'zhangsan',current_date);  
  12. MySQL> select * from userinfo; 

3.自定義函數(shù)

 
 
 
  1. MySQL> update userinfo  
  2. -> set userbirthday='2000.01.01' 
  3. -> where userid='1';  
  4. MySQL> drop function if exists fngetage;  
  5. MySQL> delimiter //  
  6. MySQL> create function fngetage(pbirthday date)  
  7. -> returns integer  
  8. -> begin  
  9. -> return year(now()) - year(pbirthday);  
  10. -> end  
  11. -> // 

4.視圖

 
 
 
  1. MySQL> create view viewuserinfo  
  2. -> as select * ,fngetage(userbirthday) as userage from userinfo;  
  3. MySQL> select * from viewuserinfo; 

清除日志記錄

 
 
 
  1. MySQL> truncate table userinfolog;  
  2. MySQL> delete from userinfolog; 

以上的相關(guān)內(nèi)容就是對MySQL 觸發(fā)器 存儲(chǔ)過程 函數(shù) 視圖的介紹,望你能有所收獲。

【編輯推薦】

  1. MySQL 數(shù)據(jù)庫開啟遠(yuǎn)程連接并不難
  2. MySQL 基本命令的用法與注意事項(xiàng)
  3. MySQL忘記密碼的正確解決方法
  4. MySQL配置SSL的實(shí)際操作流程
  5. 安裝MySQL在linux as3之下

標(biāo)題名稱:MySQL觸發(fā)器,存儲(chǔ)過程實(shí)例演示
分享URL:http://uogjgqi.cn/article/dhijogo.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們在微信上24小時(shí)期待你的聲音

解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流