mysql中on delete cascade和on update cascade级联操作

数据库外键定义的一个可选项,用来设置当主键表中的被参考列的数据发生变化时,外键表中响应字段的变换规则的

CREATE TABLE buildings ( building_no INT PRIMARY KEY AUTO_INCREMENT, building_name VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE rooms ( room_no INT PRIMARY KEY AUTO_INCREMENT, room_name VARCHAR(255) NOT NULL, building_no INT NOT NULL, FOREIGN KEY (building_no) REFERENCES buildings (building_no) ON DELETE CASCADE )ENGINE=InnoDB DEFAULT CHARSET=utf8;【当删除了buildings中的一行时,rooms表中和buildings行对应的数据内容会通过外键自动被删掉】参考自:https://www.yiibai.com/mysql/on-delete-cascade.html
阅读更多

没有更多推荐了,返回首页