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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:22:41+00:00 2026-06-10T19:22:41+00:00

I want to create a MyISAM like behavior for an InnoDB MySQL table. I

  • 0

I want to create a MyISAM like behavior for an InnoDB MySQL table. I want to have a composite primary key:

PRIMARY KEY(id1, id2)

Where id1 auto increments based on the value of id2. What’s the best way to accomplish this with InnoDB?

+----------+-------------+--------------+
|      id1 |         id2 | other_column |
+----------+-------------+--------------+
|        1 |           1 | Foo          |
|        1 |           2 | Bar          |
|        1 |           3 | Bam          |
|        2 |           1 | Baz          |
|        2 |           2 | Zam          |
|        3 |           1 | Zoo          |
+----------+-------------+--------------+
  • 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-10T19:22:43+00:00Added an answer on June 10, 2026 at 7:22 pm

    You can use this BEFORE INSERT trigger to substitute zero id-values –

    CREATE TRIGGER trigger1
      BEFORE INSERT
      ON table1
      FOR EACH ROW
    BEGIN
    
      SET @id1 = NULL;
    
      IF NEW.id1 = 0 THEN
        SELECT COALESCE(MAX(id1) + 1, 1) INTO @id1 FROM table1;
        SET NEW.id1 = @id1;
      END IF;
    
      IF NEW.id2 = 0 THEN
    
        IF @id1 IS NOT NULL THEN
          SET NEW.id2 = 1;
        ELSE
          SELECT COALESCE(MAX(id2) + 1, 1) INTO @id2 FROM table1 WHERE id1 = NEW.id1;
          SET NEW.id2 = @id2;
        END IF;
    
      END IF;
    
    END
    

    Then insert zero-values (id1 or id2) to generate new values –

    INSERT INTO table7 VALUES(0, 0, '1');
    INSERT INTO table7 VALUES(0, 0, '2');
    INSERT INTO table7 VALUES(1, 0, '3');
    INSERT INTO table7 VALUES(1, 0, '4');
    INSERT INTO table7 VALUES(1, 0, '5');
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL MyISAM table with ISBNs. I want to create a UNIQUE
I have table in mysql with MyISAM storage engine. I want to create partition
Suppose I have a simple MySQL table that looks like this: CREATE TABLE `my_table`
I've got a MySQL table that looks like this: CREATE TABLE my_facts ( `id`
I have a mysql MyISAM table with many rows that contain information about places,
I have a MySQL-table called customers1 running engine MyISAM. I've created a full text
I want to change a table from MyISAM to InnoDB. I executed ALTER TABLE
I have a mysql (5.0.22) myisam table with roughly 300k records in it and
Assuming two columns in a MySQL (MyISAM) table: title VARCHAR(1500) url VARCHAR(155) I want
I want create subdomains like this: domain.com/type/city An examples: domain.com/restaurants/new_york domain.com/hotels/new_york domain.com/restaurants/chicago I have

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.