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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:55:49+00:00 2026-05-25T18:55:49+00:00

I have an ai_order table. CREATE TABLE `ai_order`( `id` INT(11) NOT NULL AUTO_INCREMENT, `product_id`

  • 0

I have an ai_order table.

CREATE TABLE `ai_order`(
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `product_id` INT(11) NOT NULL,
    `quantity` INT(11) NOT NULL,
    `number` VARCHAR(20) NOT NULL,
    `addDate` DATETIME NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `orderProduct`(`product_id`,`number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

As an order from a client contains many product with quantity which means multiple rows being inserted for a single order, for example an order contains a 50 product being resulted in creation of 50 rows in ai_order table. now to to identify an individual order i have given a number field which will hold the unique order number (serial) for a single order i.e it will group order_id by number field. below is the table demonstrating how the data is going to be stored in the table.

ai_order

There will be many tables which will be extending from this parent table. while everything is correct the problem i see is number column repeating the value again and again, considering i have 200 product to be listed the for one order i will have to repeat the number column value again and again in all 200 rows which gives me somewhat ugly feeling.

Now the method to solve this crisis is by storing the order number in a different table.(although repetition cannot be avoided, but not a problem). for example how about removing the number column from the ai_order table and storing it this way.

CREATE TABLE `ai_order_number`(
    `order_id` INT(11) NOT NULL,
    `number` VARCHAR(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

i would like your take on how to deal with this approach? which one would you go with. the first or the later one? any suggestions on improvement will be appreciated.

thank you.

  • 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-25T18:55:50+00:00Added an answer on May 25, 2026 at 6:55 pm

    I don’t think it will be a good idea to keep a separate table as you suggested as order_number is directly related to order.

    If you are still planning to keep a different table, take ‘add_date‘ along with number. I’m finding ‘add_date‘ more uglier than order number.

    In case exact timing of adding order is not useful, which is generally the case, you can keep a separate table which will have customer_id, order_number(primary key), order_date

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

Sidebar

Related Questions

I've defined table with this schema : CREATE TABLE [dbo].[Codings] ( [Id] [int] IDENTITY(1,1)
Suppose I have an interval (a,b), and a number of subintervals {(a i ,b
I have to export an Oracle table as INSERT STATEMENTS. But the INSERT STATEMENTS
Suppose I have data in table X: id assign team ---------------------- 1 hunkim A
I have a date field in the database table of this format 2012-02-1.i need
I have a stack A and I want to create a stack B that
I have a MySQL table with an auto-increment field and I am trying to
This may seem simple, but somehow it isn't. I have a table of historical
I have the following trigger on a blackhole table, that intercepts inserts and passes
I have a table that has duplicate data for the same user_id. I need

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.