MySQL Forums
Forum List  »  InnoDB

Date check on insert.
Posted by: mitch mitch
Date: January 28, 2012 01:01PM

Hi, I was wondering how to verify if a date from a column is smaller than another date from another column.

Bascially, we'll say it's a promotion that goes on from 02-01-2012('promotion_start' column) until 03-01-2012('promotion_end' column). That is good but, what if the ending date is, 01-01-2012('promotion_end' column)?
If it's not good I would like to raise and error/exception.

I tried making a trigger but it's been a while and I could not get it to work. (Kinda rusty on triggers and I couldnt find any decent exemple about dates).
Here it is:

CREATE TRIGGER `test` BEFORE INSERT ON `promotion`
FOR EACH ROW BEGIN BEGIN IF NEW.DATE_FIN_PROMOTION < NEW.DATE_DEBUT_PROMOTION
THEN call exception('Promotion cannot end before start.); END IF; END; END;

I'm not sure where I should post this but I figured here is a good place since I use InnoDB. Also, if it matters I use HeidiSQL.

Thanks



Edited 1 time(s). Last edit at 01/28/2012 01:06PM by mitch mitch.

Options: ReplyQuote


Subject
Views
Written By
Posted
Date check on insert.
1592
January 28, 2012 01:01PM
853
January 29, 2012 09:53AM
632
January 29, 2012 10:53AM
673
January 29, 2012 10:56AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.