Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1088331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:03:28+00:00 2026-05-16T23:03:28+00:00

I’m having some problems with my stored procedure. Hope anyone can help me figure

  • 0

I’m having some problems with my stored procedure. Hope anyone can help me figure out what the problem is.

I use the data from weekly_schedule as a template for how fill my flight-table. I do this by calling CreateFlights(). All data get inserted as expected, so I’m not missing any data, but for some reason every third row is skipped despite the fact that I use auto_increment on flight.id.
(flight.id = 1,2,4,5,7,8,10,11 … 472,473,475,476…
flight.id = 3,6,9,12 etc. are not null, they’re simply just not there.)

I can’t figure out why I get the holes in the id-sequence. Can anyone help me understanding what happens? I want the flight-id’s in a continuous sequence.

Here is my code..


CREATE PROCEDURE CreateFlights()
BEGIN
  DECLARE startdate date DEFAULT curdate();
  DECLARE enddate date DEFAULT date_add(startdate, interval 367 day);

 WHILE startdate <= enddate DO
 INSERT INTO flight(`id_weekly_flights`, `flightdate`)
  (select `id`, startdate  
   from `weekly_flights`
   WHERE `name_weekdays` = dayname(startdate)
   AND `fl_year` = year(startdate));
 SET startdate = date_add(startdate, interval 1 day);
 END WHILE;
END //

CREATE TABLE weekly_flights (  
id int NOT NULL AUTO_INCREMENT,  
departuretime time,  
fl_year int,  
name_weekdays varchar(9),  
id_route varchar(8),  
PRIMARY KEY (id),  
FOREIGN KEY (name_weekdays) REFERENCES weekdays(name),  
FOREIGN KEY (id_route) REFERENCES route(id)  
)  
ENGINE=INNODB;

CREATE TABLE flight (  
id int NOT NULL AUTO_INCREMENT,  
flightdate date DEFAULT NULL,   
id_weekly_flights int,  
PRIMARY KEY (id),  
FOREIGN KEY (id_weekly_flights) REFERENCES weekly_flights(id)  
)  
ENGINE=INNODB;

INSERT INTO weekly_flights(departuretime, fl_year, name_weekdays, id_route)  
VALUES  
(073000,2010,'Monday', 'LIN2STH'),  
(073000,2010,'Monday', 'STH2LIN'),  
(073000,2010,'Friday', 'LIN2STH'),  
(073000,2010,'Friday', 'STH2LIN'),  
(210000,2010,'Sunday', 'LIN2STH'),  
(210000,2010,'Sunday', 'STH2LIN'),  
(073100,2011,'Monday', 'LIN2STH'),  
(073100,2011,'Monday', 'STH2LIN'),  
(073100,2011,'Friday', 'LIN2STH'),  
(073100,2011,'Friday', 'STH2LIN'),  
(093100,2011,'Sunday', 'LIN2STH'),  
(093100,2011,'Sunday', 'STH2LIN');
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:03:28+00:00Added an answer on May 16, 2026 at 11:03 pm

    I call a ‘non-problem’ on this.

    Are you aware of the fact, that you are not guaranteed to have consecutive auto_increment values at all? Actually, you are not guaranteed that the next auto_incremented value will be greater, than the one before it. It just works this way sometimes by coincidence.

    auto_increment is there to help you generate identity values, that’s all there is to it, really.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.