@newaitix

Почему триггер не работает?

Создал триггер. Его задача заключается в том чтоб при обновлении любой строки в таблике members проставлять у обновленной строки 11 в колонку date_access. Это не работает. Что я делаю не так?

DELIMITER //
CREATE TRIGGER `uppdate_time` BEFORE UPDATE ON `members`
FOR EACH ROW BEGIN
UPDATE `members` SET `date_access`='11' WHERE `id`=OLD.`id`;
END
  • Вопрос задан
  • 100 просмотров
Решения вопроса 2
Rsa97
@Rsa97
Для правильного вопроса надо знать половину ответа
--UPDATE `members` SET `date_access`='11' WHERE `id`=OLD.`id`;
++SET NEW.`date_access`='11';
Ответ написан
alexey-m-ukolov
@alexey-m-ukolov Куратор тега MySQL
Ваша задача проще решается другими средствами: https://dev.mysql.com/doc/refman/8.0/en/timestamp-...

For any TIMESTAMP or DATETIME column in a table, you can assign the current timestamp as the default value, the auto-update value, or both:
  • An auto-initialized column is set to the current timestamp for inserted rows that specify no value for the column.
  • An auto-updated column is automatically updated to the current timestamp when the value of any other column in the row is changed from its current value. An auto-updated column remains unchanged if all other columns are set to their current values. To prevent an auto-updated column from updating when other columns change, explicitly set it to its current value. To update an auto-updated column even when other columns do not change, explicitly set it to the value it should have (for example, set it to CURRENT_TIMESTAMP).
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы