Create a table and set up a trigger for that table.
CREATE TABLE product(
product_id INT PRIMARY KEY,
product VARCHAR(40),
entryDate DATETIME,
expDate DATETIME
);
CREATE TRIGGER test_trigger BEFORE INSERT ON `product`
FOR EACH ROW SET
NEW.entryDate = IFNULL(NEW.entryDate, NOW()),
NEW.expDate = TIMESTAMPADD(DAY, 14, NEW.entryDate);
On each insert into the table, the trigger sets the entryDate
to the current time and expDate
to 14 days time.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…