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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:12:45+00:00 2026-05-15T16:12:45+00:00

I have a table with items in it (id, name, etc) and I want

  • 0

I have a table with items in it (id, name, etc) and I want some kind of database scheme to be able to have multiple copies of the item while still being able to increment the ids. There will be a field called startdate or date_from_which_this_entry_should_be_used.

I’ve thought of two ways of implementing this:

  1. Have a table with only ids (primary key, auto-increment) and do joins to a table that has all the item information.

    Advantages:

    • easy to understand
    • hard for someone that comes after me to get confused

    Disadvantages:

    • requires more debugging and coding since this system is already in use
    • seems weird to have a table with a single field
  2. Have a single table using a sub-select to get the MAX value (+1) to apply to new items.

    Advantages:

    • single table
    • only minor code adjustments (but not all that different, maybe)

    Disadvantages:

    • prone to errors (manual increment, can’t allow deletions or the MAX value might be off)

Thanks in advance!

  • 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-15T16:12:45+00:00Added an answer on May 15, 2026 at 4:12 pm

    You should create a table called item_ids or something to generate id values. It’s okay that this has only a single column.

    CREATE TABLE item_ids (
      item_id INT AUTO_INCREMENT PRIMARY KEY
    ) ENGINE=InnoDB;
    

    You don’t even need to commit any data to it. You just use it to generate id values:

    START TRANSACTION;
    INSERT INTO item_ids DEFAULT VALUES;
    SET @id = LAST_INSERT_ID();
    ROLLBACK;
    

    So now you have a concurrency-safe method to create new id’s.

    Then you make a compound primary key for your items table. You must use MyISAM for this.

    CREATE TABLE items (
      item_id INT,
      seq_id INT AUTO_INCREMENT,
      name VARCHAR(20),
      etc VARCHAR(20),
      PRIMARY KEY (item_id, seq_id)
    ) ENGINE=MyISAM;
    

    MyISAM supports an auto-increment column in a compound primary key, which will start over at value 1 for each new item_id.* It also uses MAX(item_id)+1 so if you delete the last one, its value will be reallocated. This is unlike other use of AUTO_INCREMENT where a deleted value is not re-used.

    Whether you insert a new item, or whether you insert a new copy of an existing item, you use a similar INSERT:

    INSERT INTO items (item_id, name, etc) VALUES (@id, 'Stephane', 'etc');
    

    The @id parameter is either a value of an existing item, or else the auto-generated value you got from the item_ids table.

    * InnoDB supports auto-increment only as the first column of a primary or unique key, and it does not start over the count for each distinct value of the other column.

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

Sidebar

Related Questions

I have a table of items, user should be able to choose some of
I have two tables: Table items: | id | name | description | |
I have a table of items. item has id, score 1, score 2. I
I have multiple entries in a temporary table in Database, and I need to
I have 3 tables in my DB (MySQL). categories (name:string) items (name:string, category_id:int) votes
I have three tables filters (id, name) items(item_id, name) items_filters(item_id, filter_id, value_id) values(id, filter_id,
I have two tables in a MySql DB: items id (char) name (varchar) description
I have a table Users and a table Items In the Items table, I
I'm working on a very basic shopping cart system. I have a table items
I have a table of items stored this way : A1 | B1 A1

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.