MySQL Forums
Forum List  »  Triggers

How to create a before update trigger for 2 fields "expected_hash" and "identify_hash" (both allow null)
Posted by: Jan Marti
Date: July 01, 2021 07:26AM

Hi there

If identify_hash != expected_hash, the trigger should deny the update.

I tried EVERYTHING, but there is not solution so it seems...

Major question: Is that possible with MySQL?

I get A LOT of strange error messages like "table does not exist in field list"

Current code is that:


SET SQL_NOTES = 0;

USE pf_server;

DROP TRIGGER IF EXISTS expected_hash_trigger;

DELIMITER $$
CREATE TRIGGER expected_hash_trigger
BEFORE UPDATE ON clientdb_mapping
FOR EACH ROW

BEGIN

IF (new.identify_hash = clientdb_mapping.expected_hash) THEN
-- UPDATE clientdb_mapping SET identify_hash = clientdb_mapping.expected_hash;
DELETE FROM pi_hash_migration_mapping;
END IF;

END $$

DELIMITER ;


SET SQL_NOTES = 1;

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.