1、创建一个序列对象
1 CREATE SEQUENCE [schema_name . ] sequence_name 2 AS [ built_in_integer_type | user-defined_integer_type ]3 START WITH <constant> 4 INCREMENT BY <constant> 5 { MINVALUE [ <constant> ] } | { NO MINVALUE } 6 { MAXVALUE [ <constant> ] } | { NO MAXVALUE } 7 CYCLE | { NO CYCLE } 8 { CACHE [ <constant> ] } | { NO CACHE };
相关参数说明:
sequence_name 指定数据库中标识序列的唯一名称。 类型为 sysname。
built_in_integer_type | user-defined_integer_type 序列可定义为任何整数类型。如果未提供任何数据类型,则默认 bigint类型。
START WITH 默认值为 CACHE。
2、查询序列对象
SELECT * FROM sys.sequences
3、重置序列号
alter sequence dbo.sequence_test restart with 1; --将dbo.sequence_test重置为从1开始 select next value for dbo.sequence_test;
4、删除序列对象
drop sequence dbo.sequence_test