我目前正在开发一个项目,并且存在两个表之间保持一对一关系的数据库模式,如下所示。
--Create Table called attendence
CREATE TABLE attendence (date date NOT NULL,
epfNo varchar(10) NOT NULL,
timeIn time,
timeOut time,
PRIMARY KEY (date, epfNo))
ENGINE = InnoDB
CHARACTER SET = utf8;
--Create Table called setteams (one to one relationship with attendence)
CREATE TABLE setteams (date date NOT NULL,
epfNo varchar(10) NOT NULL,
team varchar(2),
operation varchar(100),
PRIMARY KEY (date, epfNo),
CONSTRAINT fk_setteams FOREIGN KEY (date, epfNo) REFERENCES attendence(date, epfNo) ON UPDATE CASCADE)
ENGINE = InnoDB
CHARACTER SET = utf8;
当我将数据插入到关注表时,我想根据setteam表中的一对一关系自动生成日期和epfNo值。
ON UPDATE CASCADE
在这里毫无用处。