Possible Duplicate:
Throw an error in a MySQL trigger
I have a table definition that uses CHECK
but as MySQL don't support this feature I need to do something different. The idea is to use a trigger before INSERT
or UPDATE
on this table but I'm not sure how to do it.
Here is the table:
CREATE TABLE IF NOT EXISTS `smeii_media` (
`id` INTEGER AUTO_INCREMENT,
`type` VARCHAR(5) NOT NULL,
`title` VARCHAR(100) NOT NULL,
`description` VARCHAR(500),
`path` VARCHAR(100) NOT NULL,
UNIQUE(`path`),
PRIMARY KEY(`id`),
CONSTRAINT chk_media CHECK (`type`='audio' OR `type`='image' OR `type`='video')
) ENGINE=InnoDB;
And here the trigger:
DELIMITER $$
CREATE TRIGGER smeii_media_briu BEFORE INSERT OR UPDATE FOR EACH ROW
BEGIN
IF NEW.type != 'audio' AND NEW.type != 'image' AND NEW.type != 'video'
THEN
END IF;
END;
DELIMITER $$
What can I put inside the if-block to throw an error?