1
0
mirror of synced 2025-12-25 14:37:57 +08:00
Files
SnowFlake-IdGenerator/SQL/README.md
2021-04-17 23:38:49 +08:00

29 lines
816 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ❄ idgenerator-SQL
## 介绍
这里是在不同数据库中生成雪花ID的脚本。
#### SQL Server
设计说明:
```
1.这是SQL Server的一个内置方法运行此脚本后将在SQL Server的“可编程性-函数-标量值函数”中增加一个方法 Fn_NextSnowId
2.生成的ID = 时间差 + WokerId + 随机数
时间差 = 当前时间戳(毫秒单位) - 1582136402000
WorkerId = {配置值}
随机数 = 5 至 2^SeqBigLength-1 之间的整数
3.调用方法:
例如select dbo.Fn_NextSnowId(rand())
```
在执行函数之前必须设置好以下3个参数
```
set @WorkerId = 1 -- 最大值 2^@WorkerIdBigLength-1
set @WorkerIdBigLength = 4 -- @WorkerIdBigLength+@SeqBigLength不要超过22
set @SeqBigLength = 8 -- 建议不小于6
```