Skip to content

Instantly share code, notes, and snippets.

@m4ss1m0g
Created August 23, 2023 10:27
Show Gist options
  • Save m4ss1m0g/37795ddf18ac743c4054f4bd99b57db7 to your computer and use it in GitHub Desktop.
Save m4ss1m0g/37795ddf18ac743c4054f4bd99b57db7 to your computer and use it in GitHub Desktop.
Restart SQL Server Sequence without impact DACPAC
-- Restart sequence to 1, this not impact dacpac
ALTER SEQUENCE MySequence RESTART WITH 1
-- Get all needed id to reach the desidered number, @range_first_value is mandatory
-- and returns the first (minimum or maximum) value of the sequence object used to calculate the requested range.
--
-- https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-sequence-get-range-transact-sql?view=sql-server-ver16
DECLARE @range_first_value SQL_VARIANT;
EXEC sp_sequence_get_range
@sequence_name = 'MySequence',
@range_size = 100,
@range_first_value = @range_first_value OUTPUT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment