-- Create Table
CREATE TABLE product_data (
   id int(11) unsigned NOT NULL AUTO_INCREMENT,
   product_id varchar(50) NOT NULL DEFAULT '',
   operator_id int(11) unsigned NOT NULL DEFAULT 0,
   created_on timestamp NOT NULL DEFAULT current_timestamp(),
   modified_on timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
   PRIMARY KEY (id),
   KEY operator_id (operator_id),
   KEY created_on (created_on)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Insert Data 
INSERT INTO product_data (product_id,operator_id,modified_on) VALUES ('Product_1',22,now());

-- Check Data OK
Select * from product_data ;

-- ADD Come Columns
ALTER TABLE product_data 
	ADD COLUMN add_date DATE NOT NULL DEFAULT (date(NOW())),
 	ADD COLUMN valid_until DATETIME NOT NULL DEFAULT (NOW()+ INTERVAL 1 YEAR),
    ADD CONSTRAINT chk_date_expire CHECK (valid_until > ( add_date+ INTERVAL 6 MONTH) )   ;

-- Check Data OK
Select * from product_data ;

-- DROP Come Columns
ALTER TABLE product_data 
	DROP COLUMN IF EXISTS valid_until,
    DROP COLUMN IF EXISTS add_date,
    DROP CONSTRAINT IF EXISTS date_expire   ;

-- Check Data Corrupted Now.
Select * from product_data ;