如何在 SQL Server 中制作唯一的随机字母数字序列 [英] How to make unique random alphanumeric sequence in SQL Server
本文介绍了如何在 SQL Server 中制作唯一的随机字母数字序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将唯一的随机字母数字序列作为数据库表的主键.
I want to make unique random alphanumeric sequence to be the primary key for a database table.
序列中的每个字符都是字母 (a-z) 或数字 (0-9)
Each char in the sequence is either a letter (a-z) or number (0-9)
我想要的例子:
kl7jd6fgw
zjba3s0tr
a9dkfdue3
我想做一个可以处理那个任务的函数!
I want to make a function that could handle that task!
推荐答案
您可以使用 唯一标识符.这可以使用 NEWID() 函数生成:
You can use an uniqueidentifier. This can be generated with the NEWID() function:
SELECT NEWID()
将返回类似:
BE228C22-C18A-4B4A-9AD5-1232462F7BA9
这篇关于如何在 SQL Server 中制作唯一的随机字母数字序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文