日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

《数据库系统实训》实验报告——触发器

發(fā)布時(shí)間:2024/10/5 windows 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 《数据库系统实训》实验报告——触发器 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

使用觸發(fā)器

第一部分:樣例庫(kù)的應(yīng)用

1)添加訂單物品時(shí),自動(dòng)獲取物品的價(jià)格
觸發(fā)器創(chuàng)建SQL:

create trigger auto_get_price before insert on orderitems for each row beginset new.item_price = (select prod_price from productswhere prod_id = new.prod_id); end;

測(cè)試語句:

insert into orderitems values(20006,2,'ANV02','20',0);

結(jié)果截圖:

可以看到,訂單的商品單價(jià)被觸發(fā)器修改為正確的價(jià)格,而非輸入的錯(cuò)誤數(shù)據(jù)
2)更新物品標(biāo)簽時(shí),自動(dòng)更新時(shí)間
觸發(fā)器創(chuàng)建SQL:

create trigger auto_update_datetime before update on productnotes for each row beginset new.note_date = now(); end;

測(cè)試語句:

update productnotes set note_text=concat(note_text, " new!") where note_id=102;

結(jié)果截圖:

可以看到,productnotes中note_text被修改,并且其note_date也被觸發(fā)器修改為update執(zhí)行的時(shí)間。

第二部分:所選課題數(shù)據(jù)庫(kù)的應(yīng)用

1)
觸發(fā)器創(chuàng)建SQL:

create trigger check_order before update on order for each row beginset new.amount = (select sum(total_price) from order_detailswhere order_id = new.id ); set new.totalnumber = ( select count(0) from order_detailswhere order_id = new.id ); end;

測(cè)試語句:insert into types values(‘modelx’,‘ModelX’,‘tesla’,null,null,null,‘電動(dòng)’);
結(jié)果截圖:

總結(jié)

以上是生活随笔為你收集整理的《数据库系统实训》实验报告——触发器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。