before insert
CREATE `{function_name}` BEFORE INSERT ON `{table}` FOR EACH ROW BEGIN
DECLARE rowcount INT;
SELECT COUNT(*)
INTO rowcount
FROM {table} where {field} = CURDATE();
SET NEW.{field_to_be_set} = concat( DATE_FORMAT(CURDATE(),'%y%m%d') , LPAD((rowcount + 1),4,'0'));
END;
Tidak ada komentar:
Posting Komentar