clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2335955 fiddles created (27476 in the last week).

CREATE TABLE users( user_id BIGINT(10) PRIMARY KEY AUTO_INCREMENT, user_email VARCHAR(255) NOT NULL, user_companyid BIGINT(10) NOT NULL, user_status enum('1', '0'))
 hidden batch(es)


INSERT INTO users(user_id, user_email, user_companyid, user_status) VALUES (1,'test1@gmail.com','555','1'); INSERT INTO users(user_id, user_email, user_companyid, user_status) VALUES (2,'test2@gmail.com','555','1'); INSERT INTO users(user_id, user_email, user_companyid, user_status) VALUES (3,'test1@gmail.com','777','1');
 hidden batch(es)


SELECT * FROM users;
user_id user_email user_companyid user_status
1 test1@gmail.com 555 1
2 test2@gmail.com 555 1
3 test1@gmail.com 777 1
 hidden batch(es)


CREATE TRIGGER users_before_insert BEFORE INSERT ON users FOR EACH ROW BEGIN DECLARE vUser varchar(50); -- Find username of person performing INSERT into table IF EXISTS(SELECT 1 FROM users WHERE user_email = NEW.user_email AND user_companyid = NEW.user_companyid AND user_status = 1) THEN signal sqlstate '45000' SET MESSAGE_TEXT = 'User already activated'; END IF; END;
 hidden batch(es)


INSERT INTO users( user_email, user_companyid, user_status) VALUES ('test1@gmail.com','555','1');
User already activated
 hidden batch(es)


SELECT * FROM users;
user_id user_email user_companyid user_status
1 test1@gmail.com 555 1
2 test2@gmail.com 555 1
3 test1@gmail.com 777 1
 hidden batch(es)