How to make unique random alphanumeric sequence in SQL Server

前端 未结 4 348
情话喂你
情话喂你 2021-01-16 20:21

I want to make unique random alphanumeric sequence to be the primary key for a database table.

Each char in the sequence is either a letter (a-z) or number (0-9)

4条回答
  •  被撕碎了的回忆
    2021-01-16 20:55

    You can use an uniqueidentifier. This can be generated with the NEWID() function:

    SELECT NEWID()
    

    will return something like:

    BE228C22-C18A-4B4A-9AD5-1232462F7BA9
    

提交回复
热议问题