다음 예에서 설명하는 것처럼 여러 테이블에 대해 하나의 시퀀스를 사용할 수 있습니다.
CREATE SEQUENCE dbo.MyTableID
START WITH 1
INCREMENT BY 1
NO CACHE
;
GO
CREATE TABLE dbo.[MyTable1]
(
[ID] [bigint] PRIMARY KEY NOT NULL DEFAULT (NEXT VALUE FOR dbo.MyTableID),
[Title1] [nvarchar](64) NOT NULL
);
CREATE TABLE dbo.[MyTable2]
(
[ID] [bigint] PRIMARY KEY NOT NULL DEFAULT (NEXT VALUE FOR dbo.MyTableID),
[Title2] [nvarchar](64) NOT NULL
);
--Insert 2 rows
insert into [MyTable1] (title1)
select 'title11'
insert into [MyTable1] (title1)
select 'title12';
insert into [MyTable2] (title2)
select 'title21'
insert into [MyTable2] (title2)
select 'title22';
select f1.*, 'Into MyTable1' Tb from [MyTable1] f1
union all
select f1.*, 'Into MyTable2' Tb from [MyTable2] f1
산출:
+----+---------+---------------+
| ID | Title1 | Tb |
+----+---------+---------------+
| 1 | title11 | Into MyTable1 |
| 2 | title12 | Into MyTable1 |
| 3 | title21 | Into MyTable2 |
| 4 | title22 | Into MyTable2 |
+----+---------+---------------+
sqlfiddle
cache
? 연결 링크에서 Microsoft는 사용하도록 지시합니다no cache
.