mysql触发器中使用signal

mysql触发器signal

触发器signal

DELIMITER $$
CREATE TRIGGER check_age_before_update
BEFORE update ON tbl_import_express
FOR EACH ROW
BEGIN
-- 如果插入的年龄小于 18,则抛出异常
IF NEW.status < 18 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Age must be 18 or older';
END IF;
END$$
DELIMITER ;

DELIMITER $$
CREATE PROCEDURE insert_user(IN user_name VARCHAR(100), IN user_age INT)
BEGIN
-- 如果年龄小于 18,抛出错误
IF user_age < 18 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Age must be 18 or older';
END IF;
-- 插入用户数据
INSERT INTO users (name, age) VALUES (user_name, user_age);
END$$
DELIMITER ;

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: