代码拉取完成,页面将自动刷新
set foreign_key_checks = 0;
create table dims.buildings(
BuildingID int(10) not null primary key comment "楼栋编号",
BName varchar(50) not null comment "楼栋名称",
BFloorNumber int(20) not null comment "楼层数量",
BManager varchar(50) not null comment "管理员姓名",
BMPhone varchar(15) not null comment "管理员电话"
) engine = InnoDB default charset utf8 comment "楼栋表";
set foreign_key_checks = 1;
use dims;
DELIMITER $$
CREATE TRIGGER check_floornumber # 设置触发器,1,2号楼只有8层楼;3,4号楼只有9层;5号楼只有11层
BEFORE INSERT ON dims.buildings FOR EACH ROW
BEGIN
IF NEW.BuildingID = 1 AND NEW.BFloorNumber > 8 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The Number of Floors is larger than 8';
END IF;
IF NEW.BuildingID = 2 AND NEW.BFloorNumber > 8 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The Number of Floors is larger than 8';
END IF;
IF NEW.BuildingID = 3 AND NEW.BFloorNumber > 9 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The Number of Floors is larger than 9';
END IF;
IF NEW.BuildingID = 4 AND NEW.BFloorNumber > 9 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The Number of Floors is larger than 9';
END IF;
IF NEW.BuildingID = 5 AND NEW.BFloorNumber > 11 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The Number of Floors is larger than 11';
END IF;
END$$
DELIMITER ;
insert into dims.buildings values
(1, '女1', 8, '赵阿姨', '11111111111'),
(2, '女2', 8, '钱阿姨', '22222222222'),
(3, '女3', 9, '孙阿姨', '33333333333'),
(4, '女4', 9, '李阿姨', '55555555555'),
(5, '女5', 11, '周阿姨', '66666666666');
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。