生成唯一代码 [英] Generate unique code

查看:141
本文介绍了生成唯一代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有表存储division_code和division_name。

对于每个部门代码应该是唯一的。

分部代码是自动生成的,它从EM_+第1个分部开始。



Ex:分部名称:测试 - >分部代码:EM_T

Ex:分部名称:Test1 - >分部代码:EM_Te

Ex:分部名称:终止 - >分部代码:EM_Ter



如果某些分区以相同的字母开头,如何生成唯一代码?

Hi All,

I have table in which i store division_code and division_name.
For each division code should be unique.
division code is auto generated and it starts from "EM_" + 1st letter of division.

Ex: Division Name: Test -> Division Code:EM_T
Ex: Division Name: Test1 -> Division Code:EM_Te
Ex: Division Name: Terminate -> Division Code:EM_Ter

How to generate unique code if some division starts with same letters?

推荐答案

我问了一个类似问题 [ ^ ]关于前面的唯一值,每个答案各有利弊。现在的问题是您希望您的独特价值有多长。请参阅链接上的解决方案。





编辑:

关于你的评论,为什么不只需创建分区代码的第一个字符,创建唯一代码,然后连接?以下是否足够?



I have asked a similar question[^] about unique values before and each of the answers have their own pros and cons. The question now will be how long do you want your unique values to be. Refer to the solutions on the link.



With regards to your comment, why not just create the first characters of your division code, create the unique code, and then concatenate? Will the following be sufficient?

string uniqueCode = System.Guid.NewGuid().ToString(); //E6ED1CBC-5FB3-4A1C-AD3C-5551F3836536
string divisionCode = "EM_T"; //or other value depending on your division name

// And then the final divisionCode will be divisionCode + uniqueCode, which in this case, will be
// EM_TE6ED1CBC-5FB3-4A1C-AD3C-5551F3836536


这篇关于生成唯一代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆