Reputation: 8207
I am trying to increment a field without sequence . Is there any possiblities?? can i do something like this
INSERT INTO Test
VALUES ((
SELECT COUNT(ID)
FROM Test)+1)
Please suggest me a way to do this
Upvotes: 0
Views: 7139
Reputation: 344
If your sequence field is called seq_fld for example you could use
insert into Test values ( (select max(seq_fld) from Test) + 1)
It is advisable to have unique constraint on seq_fld
Upvotes: 1
Reputation: 1921
you can take the current maximum value in a variable with @var_name = SELECT MAX(column_name) FROM TABLE
then you can make use of ROW_NUMBER() OVER (ORDER BY column_name)+@var_name
Upvotes: 1