mySQL 从 table 交易到另一个交易

mySQL transaction from on table to another with procedure

我需要创建一个包含事务的过程,该事务将 employeeID 和 AppointmentID 作为参数,然后将所有信息从约会 table 传输,其中 appointmentID 参数与约会 table 中的 appointmentID 匹配到 completed_doses table 并在同一行中另外插入 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 ;

假设 completed_doses table 与 appointment 具有相同的布局,并在末尾添加了 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