Reputation: 21
DELIMITER //
CREATE OR REPLACE TRIGGER tmVideo
BEFORE INSERT ON messages
FOR EACH ROW
BEGIN
DECLARE vurl VARCHAR(256);
SET vurl = (SELECT url FROM videos WHERE videoId = NEW.mVideoId);
IF new.mvideoId != NULL THEN INSERT INTO messagesvideos (messageId, videoId, url) VALUES (NEW.messageId, NEW.mvideoId, vurl);
END IF;
END //
DELIMITER ;
I'm trying to save on the messagesvideos
table all the messages that contain a video. I created this trigger but when I do the insert on the messages table I get no response.
Upvotes: 1
Views: 238
Reputation: 311853
null
is not a value, it's the lack thereof. You can't use =
or !=
to test for it, you should use the is
operator instead:
IF new.mvideoId IS NOT NULL THEN
-- Here ----^
INSERT INTO messagesvideos (messageId, videoId, URL)
VALUES (NEW.messageId, NEW.mvideoId, vurl);
END IF;
Upvotes: 1