I'm working on an application using JSP and MYSQL.
The application includes feature for user to input 'Date' and 'Hours', which are stored in a table 'epinfo' in MYSQL.
+-------+-------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+------------+-------+
| uid | varchar(10) | NO | PRI | | |
| dt | date | NO | PRI | 0000-00-00 | |
| hrs | int(2) | YES | | NULL | |
+-------+-------------+------+-----+------------+-------+
Another feature is applying for leave, stored in a different table 'leave'
+--------+-------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+------------+-------+
| uid | varchar(10) | NO | PRI | | |
| stdt | date | NO | PRI | 0000-00-00 | |
| enddt | date | NO | PRI | 0000-00-00 | |
+--------+-------------+------+-----+------------+-------+
I need to disable and delete any entries for this time period, in the table epinfo.
Eg. If a leave application entry is 2014-06-14 to 2014-06-16, I need to make sure the user cannot enter any data for 14,15,16th of June in the table epinfo.
I know a BEFORE INSERT Trigger can help here, which goes something like this:
create trigger cons_check
before insert on epinfo
for each row
begin
if exists(select * from leave where stdt<=entered_date and enddt>=entered_date)
then
Disable entry in database
else
insert into table.
end if
end
Can someone help me create this trigger? Or help with a different solution? Also, the entered date is the value I have in my insert query. How can I use this value in the trigger?