如何在MySQL中实现这一点:
CREATE TABLE employee (
employeemonthly DECIMAL(10,2),
employeeyearly DECIMAL(10,2) DEFAULT employeemonthly*12
);
最佳答案
使用插入触发器。像这样的东西
DELIMITER |
CREATE TRIGGER default_yearly BEFORE INSERT ON employee
FOR EACH ROW BEGIN
SET NEW.employeeyearly = NEW.employeemonthly * 12;
END;
|
DELIMITER ;