我想添加一个触发器,如果名称已更新为" NEW _"串。下面是我当前的触发器,但它的工作没有检查更新的值包含" NEW _" 。请建议
代码:
$this->execute("ALTER TABLE `users`
ADD COLUMN `date_` TIMESTAMP NULL DEFAULT NULL");
$this->execute("CREATE TRIGGER `update_user_deleted_date` BEFORE UPDATE ON `users` FOR EACH ROW BEGIN
IF (NEW.name!= OLD.name) THEN
SET NEW.date_deleted = NOW();
END IF;
END ;");
答案 0 :(得分:1)
使用此:
CREATE TRIGGER update_user_deleted_date BEFORE UPDATE ON users
FOR EACH ROW BEGIN
IF (LOCATE('NEW_', NEW.name) != 0) THEN
SET NEW.date_deleted = NOW();
END IF;
END;
LOCATE('NEW_',NEW.name)!= 0表示找到字符串“NEW_”的位置