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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:34:15+00:00 2026-06-17T09:34:15+00:00

I am creating a database on mysql. First creating the principal tables which on

  • 0

I am creating a database on mysql. First creating the principal tables which on average has 30 columns per table.
And the standard of the log table is the pk of the referenced table plus each column * 2.
Like this:

Referenced Table:

Field   |   Type      |   Null   |   Key   |   Default   |   Extra
--------+-------------+----------+---------+-------------+----------------
TableID | int(11)     | No       | PRI     | Null        | auto_increment
Col1    | varchar(50) | No       |         | Null        |

Log Table:

Field       |   Type      |   Null   |   Key   |   Default   |   Extra
------------+-------------+----------+---------+-------------+----------------
LogTableID  | int(11)     | No       | PRI     | Null        | auto_increment
TableID     | int(11)     | No       | MUL     | Null        |
NewCol1     | varchar(50) | No       |         | Null        |
UpdatedCol1 | varchar(50) | No       |         | Null        |

Now what I want is to create a procedure on which I pass the table name as a parameter and generates the creation of the table log query and executes it.

What is the best way to do this?

  • 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-06-17T09:34:16+00:00Added an answer on June 17, 2026 at 9:34 am

    To make a string represent a table (or database) name you will need to concat your query string with the variable and prepare/execute a statement right in the stored procedure. Here’s a basic example.

    -- DROP PROCEDURE IF EXISTS createLogTable;
    DELIMITER //
    CREATE PROCEDURE createLogTable(tblName VARCHAR(255))
    BEGIN
        SET @tableName = tblName;
        SET @q = CONCAT('
            CREATE TABLE IF NOT EXISTS `' , @tableName, '` (
                `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
                `something` VARCHAR(10) NOT NULL,
                `somedate` DATETIME NOT NULL,
                PRIMARY KEY (`id`)
            ) ENGINE=MyISAM DEFAULT CHARSET=utf8
        ');
        PREPARE stmt FROM @q;
        EXECUTE stmt;
        DEALLOCATE PREPARE stmt;
        -- and you're done. Table is created.
        -- process it here if you like (INSERT etc)
    END //
    

    Then… CALL createLogTable('exampleTable');

    So the basic idea is

    1. concat the procedure parameter(s) with your query as necessary
    2. prepare/execute a statement from this query string
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After dynamically creating a client-side table based on SELECT information retrieved from MySql database,
I'm using ASP.NET C# with database MYSQL, I follow this step on creating a
I am connecting C to mysql and then creating a database . My code
When creating database tables I'm often stumped when trying to name my time/date/timestamp fields.
I am creating database at runtime and I want to create the tables in
I am creating a database table with the following sql: CREATE TABLE `cs3_ds1` (
I'm creating a database table and I don't have a logical primary key assigned
I'm creating locally a big database using MySQL and PHPmyAdmin. I'm constantly adding a
I am creating a C++ application the uses a MySQL database. I would like
I need to pass data from MYSQL database to android application by creating JSON

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.