我对以下有关SQL Server中查询的正确陈述感到困惑,如下所述:
CREATE SEQUENCE Number_Sequence
AS TINYINT
START WITH 2
INCREMENT BY 3
MAXVALUE 9
以下显示的Number_Sequence
符合以下哪些条件?
此序列可以生成无限值
此序列最多只能生成3个值
此序列最多只能生成4个值
对于此序列,默认情况下MINVALUE
将设置为0
对于此序列,INCREMENT
不能为负
答案 0 :(得分:0)
CREATE SEQUENCE
调用完成,并创建了序列对象。现在,您可以从序列中获取下一个值:
SELECT NEXT VALUE FOR number_sequence
返回:2
SELECT NEXT VALUE FOR number_sequence
返回:5
SELECT NEXT VALUE FOR number_sequence
返回:8
SELECT NEXT VALUE FOR number_sequence
抛出错误:
消息11728,第16级,状态1,第7行
序列对象“ Number_Sequence”已达到其最小值或最大值。重新启动序列对象以允许生成新值。
因此您的序列可以精确地生成 3 个值-2、5和8-然后“完成”并且无法再使用.....
答案 1 :(得分:0)
正确答案为2。此序列最多只能生成3个值
尝试在SQL Server中使用以下代码
CREATE SEQUENCE Number_Sequence
AS TINYINT
START WITH 2
INCREMENT BY 3
MAXVALUE 9
SELECT NEXT VALUE FOR number_sequence
SELECT NEXT VALUE FOR number_sequence
SELECT NEXT VALUE FOR number_sequence
-- SELECT NEXT VALUE FOR number_sequence
它将显示2,5和8
如果您在查询后第4次打电话
SELECT NEXT VALUE FOR number_sequence
它将给您错误
Msg 11728, Level 16, State 1, Line 14
The sequence object 'Number_Sequence' has reached its minimum or maximum value. Restart the sequence object to allow new values to be generated.