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 7421589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:26:12+00:00 2026-05-29T08:26:12+00:00

I am trying to create a procedure which will fill up the table until

  • 0

I am trying to create a procedure which will fill up the table until certain amount of elements.

At the current moment I have

CREATE PROCEDURE PopulateTable(
    IN dbName           tinytext,
    IN tableName        tinytext,
    IN amount           INT)
BEGIN
    DECLARE current_amount INT DEFAULT 0;
    SET current_amount = SELECT COUNT(*) FROM dbName,'.',tableName;
    WHILE current_amount <= amount DO
        set @dll=CONCAT('INSERT INTO `',dbName,'`.`',tableName,'`(',
                        '`',tableName,'_name`) ',
                        'VALUES(\'',tableName,'_',current_amount,'\')');
        prepare stmt from @ddl;
        execute stmt;
        SET current_amount = current_amount + 1;
    END WHILE;
END;

So what I am trying to do is, once user calls the procedure, the function will check and see how many current elements exist, and fill up the remaining elements.

First problem I have is that I do not know how to count the elements, so my SELECT COUNT(*) FROM dbName,'.',tableName; does not work.

I also want to a suggestion since I am kind of new to databases if what I am doing is correct or if there is a better way to do this?

Also just if this is of any help the table I am trying to do this to only has 2 fields, one of them being id, which is auto incremented and is primary and the other being profile_name which I am populating.

Thanks to anyone for their help!

  • 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-29T08:26:12+00:00Added an answer on May 29, 2026 at 8:26 am
    • Firstly, I think you’ll have a delimiter problem if you try to execute the code you pasted. The procedure declaration delimiter has to be different from the one you use into the procedure code (here ‘;’). You will have to use DELIMITER statement;

    • Your procedure belongs to a schema; I’m not sure you can query tables from other shemas (especially without USE statement);

    • This is not a good idea if your database contains tables whitch are not supposed to be populated through your procedure;

    • If you have a limited number of concerned tables, I think it will be a better idea to define one procedure for each table. In this way, table name will be explicit in each procedure code and it will avoid the use of prepared statements;

    • Be careful about you ‘amount’ parameter : are you sure that your server can handle requests if I pass the maximum value for INT as amount ?

    • I think you should use ‘<‘ instead of ‘<=’ in your WHILE condition

    • If you want to insert a large number of lines, you’ll obtain better performances performing “grouped” inserts, or generating a temporary table (for example with MEMORY engine) containing all your lines and performing a unique INSERT selecting your temporary table’s content.

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

Sidebar

Related Questions

I am trying to create a sybase stored procedure which references a temp table,
I have been trying to make a stored procedure which autodeletes temporary tables. CREATE
I'm trying to create a stored procedure which will fetch data from sys.databases and
I am trying to create stored procedure which will decide which language to use
I have an already existing stored procedure. But when I am trying to create
I'm trying to create a procedure which extracts data from a MySQL server (using
I am trying to write a stored procedure in MySQL which will perform a
I'm trying to create a simple stored procedure which I can use to write
I'm trying to create DB2 trigger which is using the procedure VOTES_COUNT but when
I'm currently trying to create a PHP Thrift server which will be accessed by

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.