2

I have this current table:

CREATE TABLE IF NOT EXISTS TABLEX (
    IDX INTEGER NOT NULL,
    FK_USER INTEGER NOT NULL,
    PRIMARY KEY (IDX, FK_USER)
);

What I really want is that each insert of a FK_USER it generates the IDX for the FK, a second FK_USER should start the IDX column on 0 again.

Such:

IDX FK_USER
0   0
1   0
0   1
2   0
1   1
0   2

There's a constraint for that or the only solution is to count the previous rows to calculate it?

PS: UNIQUE INDEX doenst work for me since it will generate IDX from the previous one and not from the Composite Key

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167

0 Answers0