SQL – double column used from primary key with autoincrement

Posted on

Question :

I am user the following as primary key in the SqlDB:

I am doing the Index as Autoincrement, but it is autoincremented in general not per user.
Example userid=1,index=1, then insert another for userid=2 then inserted userid=2index=2
Then we insert a new entry for userid=2 theninserted userid=2 index=3 and not 1.

Is it possible to do what I want?

Answer :

You can’t have more than one IDENTITY column per a table.
Use MAX(index)+1 where userid=X, when inserting a new row without auto-increment.

Leave a Reply

Your email address will not be published. Required fields are marked *