We have manage to come out with the script to both create and delete partitions as below. We need help on how to backup up those partition before we launch the delete script?
IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.PARTITIONS
WHERE TABLE_NAME = 'testPart1' AND PARTITION_NAME =
CONCAT(' p'
, DATE_FORMAT( DATE_SUB( CURDATE(), INTERVAL 14 DAY ), '%Y%m%d' ))) THEN
SET @stmt := CONCAT(
'ALTER TABLE testPart1 DROP PARTITION '
, ' p'
, DATE_FORMAT( DATE_SUB( CURDATE(), INTERVAL 14 DAY ), '%Y%m%d' )
);
PREPARE stmt FROM @stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.PARTITIONS
WHERE TABLE_NAME = 'testPart1' AND PARTITION_NAME =
CONCAT(' p'
, DATE_FORMAT( DATE_ADD( CURDATE(), INTERVAL 2 DAY ), '%Y%m%d' ))) THEN
SET @stmt := CONCAT(
'ALTER TABLE testPart1 ADD PARTITION ('
, 'PARTITION p'
, DATE_FORMAT( DATE_ADD( CURDATE(), INTERVAL 2 DAY ), '%Y%m%d' )
, ' VALUES LESS THAN ('
, TO_DAYS( CURDATE() ) + 2
, '))'
);
PREPARE stmt FROM @stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
Edited 1 time(s). Last edit at 04/05/2013 04:22AM by Frwa Onto.