Auto increment ID relative to another field

1

Some time ago I was looking for something to solve this problem that I have encountered in other systems that I have developed, I would like to know a solution for how to do an auto increment id, but an auto increment related to another field, for example: I have my product table and these products are categorized, so they have a id_categoria , which references the category table and my id of the product table is auto increment , and I have a records in the table of products that would be so by example:

id | id_categoria
 1 | 1
 2 | 3
 3 | 2
 4 | 1
 5 | 2
 6 | 1
 7 | 4
 ...

But I would like this auto increment to only happen with respect to category, for example for the category of id_category I have the product of id 1,2,3,4,5, knowing that I would have to have a key primary compiler, having the product id and the category id as primary keys , my table would look something like this:

id | id_categoria
 1 | 1
 1 | 2
 1 | 3
 1 | 4
 2 | 1
 2 | 2
 3 | 1
 ...

But without first needing to consult the bank and then adding the desired id, something that was automatic done by the bank, does anyone know of any solution to this?     

asked by anonymous 23.08.2016 / 13:30

0 answers