current position:Home>Trigger implementation inserts some fields of one table into another table

Trigger implementation inserts some fields of one table into another table

2022-02-02 11:57:00 CSDN Q & A

surface A There are fields id,name,age,class,score
surface B There are fields id,name,age
How to create triggers to make tables A When a record is inserted , Insert three of these fields into the table at the same time B in




Refer to the answer 1:

Define post insert trigger .

DROP TRIGGER IF EXISTS `ins_info`; create trigger ins_info after insert on nhfxelect for each row begin  if HOUR(new.RecordTime)='20' then  insert into nhfxbyhour (UnitDepName, UnitDepCode, ElectCost, TimeJG, RecordTime)  values( ' School of Statistics ', '1', new.USERKWH, '20', new.RecordTime);  end if; end; 

Reference address :




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021156583883.html