S
S
Stanislav2018-04-17 15:51:20
MySQL
Stanislav, 2018-04-17 15:51:20

Is it possible to make auto_increment relative to another field?

Now the table looks like this:

`id` = 1, `id_user` = 2
`id` = 2, `id_user` = 2
`id` = 3, `id_user` = 1

Is it possible to auto_increment relative to the `id_user` field so that it is?
`id_user` = 2, `id` = 1
`id_user` = 2, `id` = 2
`id_user` = 1, `id` = 1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lazy @BojackHorseman MySQL, 2018-04-17
@xynd3r

myISAM only
MyISAM Notes
For MyISAM tables, you can specify AUTO_INCREMENT on a secondary column in a multiple-column index. In this case, the generated value for the AUTO_INCREMENT column is calculated as MAX(auto_increment_column) + 1 WHERE prefix=given-prefix. This is useful when you want to put data into ordered groups.

D
Dmitry Entelis, 2018-04-17
@DmitriyEntelis

By means of mysql - no.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question