DELIMITER $$

DROP TRIGGER before_desks_delete;
CREATE TRIGGER before_desks_delete
BEFORE DELETE
ON desks FOR EACH ROW
BEGIN
	DELETE FROM cards where desk_id = old.desk_id;
    INSERT INTO bin_desks
(desk_id,
desk_code,
user_id,
parent_desk,
tree,
record_desk,
import_source,
link_id,
import_open,ts_create)
    VALUES(old.desk_id,
old.desk_code,
old.user_id,
old.parent_desk,
old.tree,
old.record_desk,
old.import_source,
old.link_id,
old.import_open,old.ts_create);
END$$    

DELIMITER ;

DELIMITER $$
DROP TRIGGER before_cards_delete;
CREATE TRIGGER before_cards_delete
BEFORE DELETE
ON cards FOR EACH ROW
BEGIN
	
    INSERT INTO bin_cards
(card_id,
desk_id,
last_timing,
next_timing,
mark,
skip,
level,
record_question,
record_answer,
record_hint,
Hint,
import_source,ts_create)
VALUES(old.card_id,
old.desk_id,
old.last_timing,
old.next_timing,
old.mark,
old.skip,
old.level,
old.record_question,
old.record_answer,
old.record_hint,
old.Hint,
old.import_source,old.ts_create);
END$$    

DELIMITER ;
