sql - Automatically update record using if else in mysql table -
i new mysql , need help.
to make clearer, have 3 columns in mysql table;
- date of membership
- membership expiry
- membership status
1st , 2nd column using date format. , 3rd column using varchar.
so, i'm trying is, if expiry date exceed current date, record of 3rd column automatically changed 'expired'. , if not exceed, display 'active'.
is possible?
really appreciate if can help.
mysql supports events
. helpful when not want manually check status of each record.
example code:
delimiter $$ create event `update_status` on schedule every 1 hour begin update tablename set membershipstatus = if(curdate() > membershipexpiry, 'expired', 'active'); end $$ delimiter ;
what statement after script has been created, fired every 1 hour
interval.
to lean more events
, please see links below.
Comments
Post a Comment