Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

少量并发时在SQLServer中Sql脚本可以使用ABS(CHECKSUM(NEWID()))替代RAND() #102

Open
MrQLEO opened this issue May 21, 2024 · 0 comments

Comments

@MrQLEO
Copy link

MrQLEO commented May 21, 2024

如果不记录Sequences的话,也可以使用
ABS(CHECKSUM(NEWID()))
来尽可能保证其随机性,当然这并不能保证不会重复。
在我机器上运行了sql脚本使用rand()的方式基本上20多条就会产生重复,使用ABS(CHECKSUM(NEWID()))的话测试了10W条未产生重复值,大概在50多w的时候发生了重复。
当然相比而言ABS(CHECKSUM(NEWID()))的生成速度要比rand()慢一些,本地循环生成10W条大概在5s左右

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant