Trigger form mysql

Автор: | 17.03.2025
Создаём таблицу
CREATE TABLE email_queue (
    id INT AUTO_INCREMENT PRIMARY KEY,
    recipient VARCHAR(255),
    subject VARCHAR(255),
    message TEXT,
    sent BOOLEAN DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Создаём триггер в MySQL

DELIMITER $$

CREATE TRIGGER after_cdr_insert
AFTER INSERT ON cdr
FOR EACH ROW
BEGIN
    INSERT INTO email_queue (recipient, subject, message)
    VALUES (
        'exsmple@exsmple.com', 
        'New Call Record', 
        CONCAT('New call from ', NEW.src, ' to ', NEW.dst, ' at ', NEW.calldate)
    );
END $$

DELIMITER ;

Добавить комментарий