Hello
I have the follow table definition
( I need work mandatory with ENGINE=InnoDB due transactions control)
Code:
CREATE TABLE item (
idItem bigint(20) unsigned NOT NULL auto_increment,
idArticulo bigint(20) unsigned NOT NULL ,
texto varchar(40),
PRIMARY KEY (idItem,idArticulo)
)ENGINE=InnoDB;
consider idArticulo like the PK from a Master table
Therefore Articulo (Master Table, Father) and Item (Sub Master Table, child)
Here to fill with simple data
Code:
insert into item(idArticulo,texto)values(1,'one');
insert into item(idArticulo,texto)values(1,'two');
insert into item(idArticulo,texto)values(1,'three');
insert into item(idArticulo,texto)values(2,'one');
insert into item(idArticulo,texto)values(2,'two');
insert into item(idArticulo,texto)values(2,'three');
If I do the follow query, I get
Code:
mysql> select idarticulo,iditem,texto from item order by iditem,idarticulo;
+------------+--------+-------+
| idarticulo | iditem | texto |
+------------+--------+-------+
| 1 | 1 | one |
| 1 | 2 | two |
| 1 | 3 | three |
| 2 | 4 | one |
| 2 | 5 | two |
| 2 | 6 | three |
+------------+--------+-------+
6 rows in set (0.00 sec)
mysql>
Realize yourself that iditem is 1,2,3,4,5,6
I want some way, I dont care if is necessary edit the table, to get something like this (desired output) when I insert my items (child table)
Code:
+------------+--------+-------+
| idarticulo | iditem | texto |
+------------+--------+-------+
| 1 | 1 | one |
| 1 | 2 | two |
| 1 | 3 | three |
| 2 | 1 | one |
| 2 | 2 | two |
| 2 | 3 | three |
+------------+--------+-------+
Code:
Realize yourself that iditem is 1,2,3 and 1,2,3 according for each idarticulo
I mean, each Master table (for each PK) has
its own control from its childs (for its FK)
Please I need a way to work in this, I would have 3 buildings/local in different places on my city working in real time, I need strict control for this generation for the fields, I assume that MySQL latest versions perhaps would handle this situation
Thanx