sql >> Database >  >> RDS >> Mysql

Variabele MySQL-trigger declareren

Alle VERKLARINGEN moeten bovenaan staan. dwz.

delimiter //

CREATE TRIGGER pgl_new_user 
AFTER INSERT ON users FOR EACH ROW
BEGIN
    DECLARE m_user_team_id integer;
    DECLARE m_projects_id integer;
    DECLARE cur CURSOR FOR SELECT project_id FROM user_team_project_relationships WHERE user_team_id = m_user_team_id;

    SET @m_user_team_id := (SELECT id FROM user_teams WHERE name = "pgl_reporters");

    OPEN cur;
        ins_loop: LOOP
            FETCH cur INTO m_projects_id;
            IF done THEN
                LEAVE ins_loop;
            END IF;
            INSERT INTO users_projects (user_id, project_id, created_at, updated_at, project_access) 
            VALUES (NEW.id, m_projects_id, now(), now(), 20);
        END LOOP;
    CLOSE cur;
END//


  1. hoe de laatste invoeg-ID te krijgen na invoegquery in codeigniter actieve record

  2. Doorzoek alle velden in alle tabellen voor een specifieke waarde (Oracle)

  3. Hoe RTRIM_ORACLE() werkt in MariaDB

  4. Node.js mysql-transactie