The code for while.sql is: CREATE TABLE calendars( id INT AUTO_INCREMENT, fulldate DATE UNIQUE, day TINYINT NOT NULL, month TINYINT NOT NULL, quarter TINYINT NOT NULL, year INT NOT NULL, PRIMARY KEY(id) ); DELIMITER $$ CREATE PROCEDURE InsertCalendar(dt DATE) BEGIN INSERT INTO calendars( fulldate, day, month, quarter, year ) VALUES( dt, EXTRACT(DAY FROM dt), EXTRACT(MONTH FROM dt), EXTRACT(QUARTER FROM dt), EXTRACT(YEAR FROM dt) ); END$$ DELIMITER ; DELIMITER $$ CREATE PROCEDURE LoadCalendars( startDate DATE, day INT ) BEGIN DECLARE counter INT DEFAULT 1; DECLARE dt DATE DEFAULT startDate; WHILE counter <= day DO CALL InsertCalendar(dt); SET counter = counter + 1; SET dt = DATE_ADD(dt,INTERVAL 1 day); END WHILE; END$$ DELIMITER ; CALL LoadCalendars('2019-01-01',31);