Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bulk increment sequence within MS SQL Server

Tags:

sql

sql-server

Postgres and Oracle include generate_series/connect by command to allow incrementing a sequence by more than 1. I have a need to increment a sequence by a variable amount before row insertion. For example in Postgres this would look like the query below:

select nextval('mytable_seq') from generate_series(1,3);

What would be the recommended way to accomplish this in Microsoft SQL Server?

like image 420
user1002346 Avatar asked Aug 27 '26 08:08

user1002346


1 Answers

There is a stored procedure call you can use. Alternatively, you could set up some sort of while loop that calls next value for multiple times and caches them for use later.

like image 144
Kittoes0124 Avatar answered Aug 28 '26 22:08

Kittoes0124



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!