What is the best method of exporting SQL Server 2012 Sequence objects from one instance to another instance? Is there something similar to the bcp utility that is used for table data?
We have several hundred to transfer. I need to maintain the next value since we are moving table data as well.
One possibility would be to have your system create SQL scripts that you can then execute on the other system - something like this:
SELECT
'CREATE SEQUENCE ' + seq.name + ' AS ' + t.name +
' START WITH ' + CAST(seq.current_value AS VARCHAR(20)) +
' INCREMENT BY ' + CAST(seq.increment AS VARCHAR(10))
FROM
sys.sequences seq
INNER JOIN
sys.types t ON seq.system_type_id = t.system_type_id
Running this SQL on a given database produces an output that contains CREATE SEQUENCE statement to re-create the sequences, using the current_value as the starting point, and using the defined Increment By value.
Of course, if you need additional options like CYCLE or NO CYCLE etc. - everything that's contained in the sys.sequences catalog view can be scripted out as needed :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With