Create Event that will run every day at 23:30:01 and get all data from table A and copy to table B.
In this case my first table is A and copy yesterday data form table A to table B.
Step 1: Create table A
CREATE TABLE `A` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`image` varchar(150) DEFAULT NULL,
`user_id` int(11) DEFAULT NULL,
`created` date DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Step 2: Create table B
CREATE TABLE `B` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`image` varchar(150) DEFAULT NULL,
`user_id` int(11) DEFAULT NULL,
`created` date DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Step 3:
CREATE EVENT `copy_yesterday_data_from_A_to_B` ON SCHEDULE EVERY 1 DAY STARTS '2017-06-13 23:30:01' ON COMPLETION PRESERVE ENABLE COMMENT 'Copy_Data_A_To_B'
DO BEGIN
INSERT INTO `B` (
`image`,`user_id`, `created` )
SELECT `image`, `user_id`, `created`
FROM `A`
WHERE `created` =CURDATE() - INTERVAL 1 DAY ;
END $$
DELIMITER ;
Thats it.
Note : Do not forget to include delimiter ; at end of event.
For any query email at pankajtec@gmail.com
Comments
Post a Comment