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 :-)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.