create table tbl_order_detail(
o_detail_id int NOT NULL AUTO_INCREMENT,
o_id int NOT NULL,
p_id int NOT NULL,
user_qty int NOT NULL,
total int NOT NULL,
primary key(o_detail_id),
foreign key(o_id) references tbl_order(o_id),**strong text**
foreign key(p_id) references tbl_product(p_id));
------------------------------------------------------------------------------
create procedure user_buy_item1(o_id int,pid int,user_qty int,total int)
begin
DECLARE total_products INT DEFAULT 0;
DECLARE new_total INT DEFAULT 0;
insert into tbl_order_detail values(null,o_id,pid,user_qty,total);
select p_qty into total_products from tbl_product where p_id = pid;
set new_total = total_products - user_qty;
update tbl_product set p_qty = new_total where p_id = pid;
end
错误 SQL查询:
create procedure user_buy_item1(o_id int,pid int,user_qty int,total int)
begin
DECLARE total_products INT DEFAULT 0
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3 **
答案 0 :(得分:0)
尝试更改您的插入查询
insert into tbl_order_detail(o_id,p_id , user_qty, total ) values(o_id,pid,user_qty,total);