本文介绍了MySQL:在错误的架构中触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
delimiter //
CREATE TRIGGER `range` BEFORE INSERT ON touristCompany.hotels
FOR EACH ROW
BEGIN
IF NEW.star >5 THEN
SET NEW.star = 5;
ELSEIF NEW.star < 1 THEN
SET NEW.star = 1;
END IF;
END;//
delimiter ;
推荐答案
您需要在发生插入操作的相同架构/数据库中创建触发器.从触发器定义中可以明显看出,触发器操作将在touristCompany
数据库下.确保您在同一数据库下创建触发器.
You need to create the trigger within the same schema/database where the insert operation is happening. From your trigger definition it's obvious that trigger operation will be under touristCompany
database. Make sure you are creating the trigger under same database.
按如下所示修改触发器定义
Modify your trigger definition like below
delimiter //
CREATE TRIGGER `touristCompany`.`range`
BEFORE INSERT ON `touristCompany`.`hotels`
FOR EACH ROW
BEGIN
IF NEW.star > 5 THEN
SET NEW.star = 5;
ELSEIF NEW.star < 1 THEN
SET NEW.star = 1;
END IF;
END;//
delimiter ;
(OR)在创建触发器之前选择数据库
(OR) Select the database before creating trigger
USE `touristCompany`;
delimiter //
CREATE TRIGGER `range` ...
<rest of code here>
这篇关于MySQL:在错误的架构中触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!