我想从我的序列中获取当前值 - 与序列属性窗口 SQL Server Management Studio 中显示的值相同
我的序列是用这个语句创建的:
CREATE SEQUENCE [OrderNumberSequence]
as int
START WITH 4000
INCREMENT BY 1
MINVALUE 0
NO MAXVALUE
NO CACHE;
GO
我从 MSDN尝试过这个 SQL——但结果是每次运行查询时我的数字都会增加 5
DECLARE
@FirstSeqNum sql_variant
, @LastSeqNum sql_variant
, @CycleCount int
, @SeqIncr sql_variant
, @SeqMinVal sql_variant
, @SeqMaxVal sql_variant ;
EXEC sys.sp_sequence_get_range
@sequence_name = N'[OrderNumberSequence]'
, @range_size = 5
, @range_first_value = @FirstSeqNum OUTPUT
, @range_last_value = @LastSeqNum OUTPUT
, @range_cycle_count = @CycleCount OUTPUT
, @sequence_increment = @SeqIncr OUTPUT
, @sequence_min_value = @SeqMinVal OUTPUT
, @sequence_max_value = @SeqMaxVal OUTPUT ;
-- The following statement returns the output values
SELECT
@FirstSeqNum AS FirstVal
, @LastSeqNum AS LastVal
, @CycleCount AS CycleCount
, @SeqIncr AS SeqIncrement
, @SeqMinVal AS MinSeq
, @SeqMaxVal AS MaxSeq ;
有没有办法在不改变数字的情况下获得价值?