From 47bcfe4001cc4621d1d9922adbe0ed690ae831fe Mon Sep 17 00:00:00 2001 From: yitter Date: Sun, 18 Apr 2021 01:26:08 +0800 Subject: [PATCH] auto commit --- SQL/README.md | 11 ++++++++--- SQL/sqlserver.sql | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/SQL/README.md b/SQL/README.md index 91de79a..1307a81 100644 --- a/SQL/README.md +++ b/SQL/README.md @@ -2,7 +2,7 @@ ## 介绍 -这里是在不同数据库中生成雪花ID的脚本。 +这里是在不同数据库中生成雪花ID的SQL脚本。 #### SQL Server @@ -27,6 +27,11 @@ 在执行函数之前,必须设置好以下3个参数: ``` set @WorkerId = 1 -- 最大值 2^@WorkerIdBigLength-1 -set @WorkerIdBigLength = 4 -- @WorkerIdBigLength+@SeqBigLength,不要超过22 -set @SeqBigLength = 8 -- 建议不小于6 +set @WorkerIdBigLength = 4 -- 规则约束:@WorkerIdBigLength+@SeqBigLength<23 +set @SeqBigLength = 8 -- 建议不小于6,在当前SQL版本中,@SeqBigLength 决定随机数的最大值(未采用自增数,这需要数据表记录Seq值) ``` + +#### 其它思路 + +除了用SQL Server方法生成雪花ID之外,还可让SQL Server调用外部dll生成ID。参考:https://www.cnblogs.com/woxpp/p/3990277.html + diff --git a/SQL/sqlserver.sql b/SQL/sqlserver.sql index 0146368..46d7153 100644 --- a/SQL/sqlserver.sql +++ b/SQL/sqlserver.sql @@ -37,8 +37,8 @@ begin -- Begin: ҪʼIJȷ @WorkerIdBigLength @SeqBigLength ֵӦóͬ set @WorkerId = 1 -- ֵ 2^@WorkerIdBigLength-1 - set @WorkerIdBigLength = 4 -- @WorkerIdBigLength+@SeqBigLength<23 - set @SeqBigLength = 8 -- 鲻С6 + set @WorkerIdBigLength = 4 -- Լ@WorkerIdBigLength+@SeqBigLength<23 + set @SeqBigLength = 8 -- 鲻С6ڵǰSQL汾У@SeqBigLength ֵδҪݱ¼Seqֵ -- End -- ǰʱ뵥λ