sql >> Database teknologi >  >> RDS >> Mysql

Sådan opretter du en trigger for sletning af php myadmin

Du skal indstille afgrænseren til noget andet end ;

DELIMITER |
CREATE TRIGGER blockuserundo BEFORE DELETE ON user_blocked
FOR EACH ROW BEGIN
UPDATE members SET ty_status = '1' WHERE user_id = OLD.block_user_id ;
END;
|
DELIMITER ;

Koden nedenfor fungerer som forventet:

DROP TABLE IF EXISTS user_blocked;
CREATE TABLE user_blocked 
(
    block_user_id INT
);
DROP TABLE IF EXISTS members;
CREATE TABLE members 
(
    user_id INT,
    ty_status CHAR(1)
);

INSERT user_blocked
VALUES (1),(2),(3),(4),(5);

INSERT members
VALUES (1, '0'),(2, '0'),(3, '0'),(8, '0'),(9, '1');

DELIMITER |
CREATE TRIGGER blockuserundo BEFORE DELETE ON user_blocked
FOR EACH ROW BEGIN
UPDATE members SET ty_status = '1' WHERE user_id = OLD.block_user_id ;
END;
|
DELIMITER ;

SELECT * FROM members;

DELETE FROM user_blocked WHERE block_user_id IN(1,2);
SELECT * FROM members;



  1. 3 måder at kontrollere en kolonnes datatype i PostgreSQL

  2. Hvordan registreres ikke-standardiserede SQL-funktioner manuelt i Spring Boot-applikationen?

  3. int(11) vs. int(alt andet)

  4. Hvordan indlæser jeg en lokal .SQL-fil i MySQL?