[英]SQL Server Export / Import Sequences
What is the best method of exporting SQL Server 2012 Sequence
objects from one instance to another instance? 将SQL Server 2012
Sequence
对象从一个实例导出到另一个实例的最佳方法是什么? Is there something similar to the bcp utility that is used for table data? 是否有类似于用于表数据的bcp实用程序?
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: 一种可能性是让您的系统创建SQL脚本然后可以在另一个系统上执行 - 如下所示:
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. 在给定数据库上运行此SQL会生成一个输出,该输出包含
CREATE SEQUENCE
语句以重新创建序列,使用current_value
作为起始点,并使用定义的Increment By
值。
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 :-) 当然,如果你需要其他选项,比如
CYCLE
或NO CYCLE
等等 - sys.sequences
目录视图中包含的所有内容都可以根据需要编写脚本:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.