IDENTITY(1, 1)는 메모리 최적화 테이블에서 지원됩니다. 그러나 X != 1 또는 y != 1이 있는 IDENTITY(x, y)의 정의가 있는 ID 열은 메모리 최적화 테이블에서 지원되지 않습니다. IDENTITY 값에 대한 해결 방법은 SEQUENCE 개체(시퀀스 번호)를 사용합니다.
먼저 변환할 테이블에서 IDENTITY 속성을 In-Memory OLTP로 제거합니다. 그런 다음 테이블의 열에 대한 새 SEQUENCE 개체를 정의합니다. ID 열인 SEQUENCE 개체는 NEXT VALUE FOR 구문을 사용하여 새 ID 값을 가져오는 열에 대한 DEFAULT 값을 만드는 기능을 사용합니다. In-Memory OLTP에서는 DEFAULT가 지원되지 않으므로 새로 생성된 SEQUENCE 값을 INSERT 문이나 삽입을 수행하는 고유하게 컴파일된 저장 프로시저에 전달해야 합니다. 다음 예제에서는 이 패턴을 보여 줍니다.
-- Create a new In-Memory OLTP table to simulate IDENTITY insert
-- Here the column C1 was the identity column in the original table
--
create table T1
(
[c1] integer not null primary key T1_c1 nonclustered,
[c2] varchar(32) not null,
[c3] datetime not null
) with (memory_optimized = on)
go
-- This is a sequence provider that will give us values for column [c1]
--
create sequence usq_SequenceForT1 as integer start with 2 increment by 1
go
-- insert a sample row using the sequence
-- note that a new value needs to be retrieved form
-- the sequence object for every insert
--
declare @c1 integer = next value for [dbo].[usq_SequenceForT1]
insert into T1 values (@c1, 'test', getdate())
삽입을 여러 번 수행한 후 [c1] 열에 유효한 단조로 증가하는 값이 표시됩니다. 이 결과 집합은 ORDER BY
없이 테이블 검색 및 해시 인덱스를 사용하여 생성되었기 때문에 행이 정렬되지 않습니다.