1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SQL Server シーケンス番号(連番)をINSERTする方法

Posted at

SQL Serverにてシーケンス番号(連番)をINSERTする方法のメモ書きです。

CREATE SEQUENCE [schema_name . ] sequence_name
    [ AS [ built_in_integer_type | user-defined_integer_type ] ]
    [ START WITH value ]
    [ INCREMENT BY value ]
    [ { MINVALUE value } | { NO MINVALUE } ]
    [ { MAXVALUE value } | { NO MAXVALUE } ]
    [ CYCLE | { NO CYCLE } ]
    [ { CACHE value } | { NO CACHE } ]
CREATE SEQUENCE dbo.number_sequence
START WITH 1
INCREMENT BY 1;

number_sequenceという連番を作成
1から始まる
増分は1

SQL Server Management Studioのエクスプローラー内にシーケンスが作成されている

image.png

INSERT INTO dbo.テーブル名(シーケンス番号)
VALUES(NEXT VALUE FOR number_sequence);

上記SQLでシーケンスをINSERTできます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?