Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add trigger to prevent insert duplicate domain with status = 1 #77

Closed
wants to merge 2 commits into from

Conversation

Akhilesh1004
Copy link
Contributor

No description provided.

@LeeLin2602
Copy link
Contributor

Please provide SQL statements like below next time:

DELIMITER $$

CREATE TRIGGER before_insert_domains
BEFORE INSERT ON domains FOR EACH ROW
BEGIN
    IF NEW.status = 1 AND (
        SELECT COUNT(*)
        FROM domains
        WHERE domain = NEW.domain AND status = 1
    ) > 0 THEN
        SIGNAL SQLSTATE '45000'
        SET MESSAGE_TEXT = 'This domain has been registered';
    END IF;
END$$

DELIMITER ;

@LeeLin2602 LeeLin2602 closed this Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants