Answers:
将其分配为列的默认属性
CREATE TABLE [MyTable]
(
[ID] [bigint] PRIMARY KEY NOT NULL DEFAULT (NEXT VALUE FOR dbo.MyTableID),
[Title] [nvarchar](64) NOT NULL
);
将来的读者,如果服务意外停止,则Sequence 可能会有空白,因此CACHE中实体的值可能会丢失。在这里,他们指定no cache
通过对序列对象降低性能的权衡来减轻这种情况。
创建序列参考
您可以将一个序列用于多个表,如以下示例所示:
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 |
+----+---------+---------------+
cache
在这种情况下使用安全吗?在连接链接上,Microsoft告诉我们使用no cache
。