If I have a table A with column INCREMENT_NUMBER. We will say that there are five rows.
1
2
3
4
4
If a user adds a new row to table A, the INCREMENT_NUMBER column of that row should be 5. (It could be anything, as long as it isn’t a number 1-4.) Keep in mind
INCREMENT_NUMBER integer auto_increment primary key
will not work because I need to allow for duplicates in the table and I don’t think
insert
If you want to allow duplicates, don’t declare it as a
PRIMARY KEY(and neither put aUNIQUEconstraint on it).In MySQL an
AUTO_INCREMENTis allowed to have duplicates in that case – you just have to add a simple index on it:Test in SQL-Fiddle: test-1
Results in:
In SQL-Server, you’ll have to toggle the
IDENTITY_INSERTsettingONandOFFto have similar behaviour:And then test-2:
Results in: