从主键生成唯一代码

编程入门 行业动态 更新时间:2024-10-17 15:22:23
本文介绍了从主键生成唯一代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个订单表,我想为用户提供一个唯一的订单代码,同时隐藏递增的身份整数主键,因为我不想透露已下订单的数量.

I have a table of orders and I want to give users a unique code for an order whilst hiding the incrementing identity integer primary key because I don't want to give away how many orders have been made.

确保代码唯一的一种简单方法是使用主键来确定代码.

One easy way of making sure the codes are unique is to use the primary key to determine the code.

那么我怎样才能将一个整数转换成一个友好的,比如说,八位字母数字代码,这样每个代码都是唯一的?

So how can I transform an integer into a friendly, say, eight alpha numeric code such that every code is unique?

推荐答案

假设创建的订单总数不会接近池中标识符的总数,一个相当有效的技术是简单地生成一个随机标识符,看看它是否已经被使用;继续生成新的标识符,直到找到以前没有使用过的标识符.

Assuming the total number of orders being created isn't going to get anywhere near the total number of identifiers in your pool, a reasonably effective technique is to simply generate a random identifier and see if it is used already; continue generating new identifiers until you find one not previously used.

更多推荐

从主键生成唯一代码

本文发布于:2023-11-17 02:36:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608493.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主键   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!