CREATE TABLE `tb_loan_bk` like tb_loan;
insert into tb_loan_bk select * from tb_loan;
truncate tb_loan;
CREATE TABLE `tb_loan_tmp` like tb_loan;
insert into tb_loan_tmp 
(uid, barcode,maxRenewal, dateLoan,dateDue,dateRenewal, dateReturn, renewalCount,finerate,status,type,teacherScheduleId,teacherName,courseName) 
select
uid, barcode,maxRenewal, dateLoan,dateDue,dateRenewal, dateReturn, renewalCount,finerate,status,type,teacherScheduleId,teacherName,courseName
from tb_loan_fromOpl;
insert into tb_loan_tmp 
(uid, barcode,maxRenewal, dateLoan,dateDue,dateRenewal, dateReturn, renewalCount,finerate,status,type,teacherScheduleId,teacherName,courseName)
select uid, barcode,maxRenewal, dateLoan,dateDue,dateRenewal, dateReturn, renewalCount,finerate,status,type,teacherScheduleId,teacherName,courseName from tb_loan_bk ;
insert into tb_loan (uid, barcode,maxRenewal, dateLoan,dateDue,dateRenewal, dateReturn, renewalCount,finerate,status,type,teacherScheduleId,teacherName,courseName)
select uid, barcode,maxRenewal, dateLoan,dateDue,dateRenewal, dateReturn, renewalCount,finerate,status,type,teacherScheduleId,teacherName,courseName
from tb_loan_tmp order by dateLoan;



