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.

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.
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