请大佬帮帮忙

淡丶 2017-12-23 10:00:16
求告知这题怎么做::

创建触发器ord_upd,实现当向lineitem表插入一行数据时,根据订单号对orders表的订单总价进行修改,订单总价加上该商品明细的金额。并验证触发器

表中的语句
create table orders
(
orderid int not null auto_increment primary key,
userid char(6) not null ,
orderdate datetime not null , -- 当前日期!--
totalprice decimal(10,2),
status tinyint null -- 订单是否处理 1表示处理 0表示待处理!--
)

create table lineitem
(
orderid int not null ,
itemid char(10) not null ,
quantity int not null ,
unitprice decimal(10,2) not null ,
primary key(orderid,itemid,quantity)
)
insert into orders (orderid,userid,orderdate,totalprice,status) VALUES
(20170911,'u001','2017-09-25 12:06:34','','0'),
(20170912,'u002','2017-09-25 15:04:45','','0'),
(20170913,'u003','2017-09-25 17:26:52','','0'),
(20170914,'u003','2017-09-25 18:07:04','','1'),
(20170915,'u004','2017-09-26 09:16:24','','0')


insert into lineitem (orderid,itemid,quantity,unitprice) values
(20170911,'FI-SW-01',10,'12'),
(20170911,'FI-SW-02',12,'20'),
(20170912,'K9-BD-01',2,'1600'),
(20170912,'K9-PO-02',1,'2600'),
(20170913,'K9-DL-01',1,'3500'),
(20170914,'RP-SN-01',2,'240'),
(20170915,'AV-SB-02',2,'50')
...全文
195 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 2017-12-25
  • 打赏
  • 举报
回复
淡丶 2017-12-24
  • 打赏
  • 举报
回复 1
已经解决 delimiter// create trigger ord_upd after insert on lineitem for each row begin declare tota decimal(10,2); select (quantity * unitprice) into tota from lineitem where orderid = new.orderid; update orders set totalprice =totalprice +tota where orderid = (select orderid from lineitem where orderid = new.orderid); end// delimiter;

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧