【问题标题】:mySQL transaction from on table to another with procedure使用过程从一个表到另一个表的 mySQL 事务
【发布时间】:2021-04-16 14:47:27
【问题描述】:

我需要创建一个带有事务的过程,该事务以employeeID 和AppointmentID 作为参数,然后将所有信息从约会表中的约会表中的约会ID 参数与约会表中的约会ID 匹配的所有信息传输到completed_doses 表中,并另外插入employeeID 参数。行。

这是我目前的代码:

enter code here
DELIMITER //
create procedure appointment_finished (in employeeID  mediumint, in appointmentID int(10)) 
begin 
declare vSQLSTATE char(5) default '00000';
declare continue handler for sqlexception
begin 
get diagnostics condition 1
vSQLSTATE = returned_SQLSTATE;
end;
start transaction;
insert into completed_doses 
select
(select *
from appointment
where appointmentID = appointment.appointmentID),
(employeeID);
select vSQLSTATE;
if vSQLSTATE = '00000' then commit;
else rollback;
end if;
end //
DELIMITER ;

【问题讨论】:

    标签: mysql transactions procedure


    【解决方案1】:

    假设 completed_doses 表的布局与约会相同,并在末尾加上列employeeID;并假设您需要在同一行中包含员工 ID:

    这段代码

    insert into completed_doses 
    select
    (select *
    from appointment
    where appointmentID = appointment.appointmentID),
    (employeeID)
    

    应该是

    insert into completed_doses 
    select *,employeeID 
    from appointment
    where appointmentID = appointment.appointmentID
    

    【讨论】:

    • 感谢您的帮助。像魅力一样工作!
    • 不客气,您能接受答案和/或投票吗?
    • 肯定的朋友
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 2023-03-03
    • 2013-11-18
    • 2015-05-17
    • 2012-08-12
    相关资源
    最近更新 更多