Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
721 B
1
Indexable
Never
DELIMITER //

CREATE PROCEDURE AddUserAndList(IN user_login VARCHAR(255), IN user_full_name VARCHAR(255), IN list_name VARCHAR(255), IN list_description VARCHAR(255))
BEGIN
    DECLARE user_id INT;
    DECLARE list_id INT;

    -- Начало транзакции
    START TRANSACTION;

    -- Добавление пользователя
    INSERT INTO users (login, full_name) VALUES (user_login, user_full_name);
    SET user_id = LAST_INSERT_ID();

    -- Добавление рассылки
    INSERT INTO maillist (list_name, description) VALUES (list_name, list_description);
    SET list_id = LAST_INSERT_ID();

    -- Коммит транзакции
    COMMIT;
END //

DELIMITER ;
Leave a Comment