SQL Server 自增长序列

一、创建序列

-- =============================================
-- 【QDDBD】:序列名称
--  从1开始,每次增长1
-- =============================================
create sequence E3_QDDBD as bigint
    start with 1
    increment by 1;
GO

二、使用方法

  1. 查询使用

select (next value for E3_QDDBD)

  2. 设置字段默认值

declare @tables table(
    iID bigint default((next value for E3_QDDBD))
)

三、说明备注

  1. 序列是存储在系统表【sys.sequences】

select * from sys.sequences where [Name] = 'E3_QDDBD'

  2. 更新序列值

--重置序列从1开始
alter sequence dbo.E3_QDDBD restart with 1;

 

select * from 

posted @ 2021-01-26 11:13  浩叔  阅读(838)  评论(0编辑  收藏  举报