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

  • SEARCH
  • Home
  • 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 7669917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:42:14+00:00 2026-05-31T15:42:14+00:00

I have three tables. Project(Id), attribute(Id), project_attribute(Id, project_id, attribute_id) . I want to create

  • 0

I have three tables.
Project(Id), attribute(Id), project_attribute(Id, project_id, attribute_id).

I want to create records in project_attribute table by using all attributes from attribute table to each project from project table.

To create such records i am using following store procedure.

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `proj_attr`()
BEGIN   
    DECLARE proj_done, attribute_done BOOLEAN DEFAULT FALSE;    
    declare attributeId int(11) default 0;
    declare  projectId int(11) default 0;
    DECLARE curProjects CURSOR FOR SELECT id FROM project order by id;  
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET proj_done = TRUE;

    OPEN curProjects;
    cur_project_loop: LOOP
    FETCH FROM curProjects INTO projectId;

        IF proj_done THEN
        CLOSE curProjects;
        LEAVE cur_project_loop;
        END IF;

        BLOCK2: BEGIN
        DECLARE curAttribute CURSOR FOR SELECT id FROM attribute order by id;
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET attribute_done = TRUE;
        OPEN curAttribute; 
        cur_attribute_loop: LOOP
        FETCH FROM curAttribute INTO attributeId;   
            IF attribute_done THEN
            CLOSE curAttribute;
            LEAVE cur_attribute_loop;
            END IF; 
            insert into project_attribute_value(project_id, attribute_id)
                values(projectId, attributeId); 
        END LOOP cur_attribute_loop;
        END BLOCK2;
    END LOOP cur_project_loop;


    END$$

DELIMITER ;

But, this procedure is creating records only for 1 project in project_attribute table even though there are 50 projects in Project table. Expected record count is count(projectId)*count(attributeId).

  • 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-31T15:42:15+00:00Added an answer on May 31, 2026 at 3:42 pm

    Try this, this will surely solve your issue.

    DELIMITER $$
    CREATE DEFINER=`root`@`localhost` PROCEDURE `proj_attr`()
    BEGIN   
        DECLARE proj_done, attribute_done BOOLEAN DEFAULT FALSE;    
        declare attributeId int(11) default 0;
        declare  projectId int(11) default 0;
        DECLARE curProjects CURSOR FOR SELECT id FROM project order by id;  
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET proj_done = TRUE;
    
        OPEN curProjects;
        cur_project_loop: LOOP
        FETCH FROM curProjects INTO projectId;
    
            IF proj_done THEN
            CLOSE curProjects;
            LEAVE cur_project_loop;
            END IF;
    
            BLOCK2: BEGIN
            DECLARE curAttribute CURSOR FOR SELECT id FROM attribute order by id;
            DECLARE CONTINUE HANDLER FOR NOT FOUND SET attribute_done = TRUE;
            OPEN curAttribute; 
            cur_attribute_loop: LOOP
            FETCH FROM curAttribute INTO attributeId;   
                IF proj_done THEN
                set proj_done = false;
                CLOSE curAttribute;
                LEAVE cur_attribute_loop;
                END IF; 
                insert into project_attribute_value(project_id, attribute_id)
                    values(projectId, attributeId); 
            END LOOP cur_attribute_loop;
            END BLOCK2;
        END LOOP cur_project_loop;
    
    
        END$$
    
    DELIMITER ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using MySQL, I have three tables: projects : ID name 1 birthday party 2
I have three tables in the many-to-many format. I.e, table A, B, and AB
I have three tables: project (idproject, name) color (idcolor, name) project_has_color (idproject, idcolor) Now
I have three tables: one indexed by the names of projects (PROJECT) one indexed
I have three tables: $sTable = a table of songs (songid, mp3link, artwork, useruploadid
I have three tables: page, attachment, page-attachment I have data like this: page ID
I have three tables tag , page , pagetag With the data below page
I have three tables like that: Articles IdArticle Title Content Tags IdTag TagName ContentTag
I have three tables. This query will write down the right answer (x-lines for
I have three tables in my DB (actually a few more than that) these

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.