I would like to have unique generated primary key that will take info from other field to create that code. For example, let say I would like to generate student ID based on year, and student's name, so my code will consist of string that has 3 letter and 4 digit. Student name: Jone year: 2015 so the generated code will be something like: jon2015

我想拥有唯一生成的主键,它将从其他字段获取信息以创建该代码。例如,假设我想根据年份和学生的姓名生成学生ID,因此我的代码将包含3个字母和4个数字的字符串。学生姓名:Jone年份:2015所以生成的代码将类似于:jon2015

Please advice me how I should do it?

请告诉我应该怎么做?

1 个解决方案

#1


0

I built a Student Info System based on MySQL. I can tell you right away that building a unique ID based off a date and a name is the fastest way to get duplicates.

我建立了一个基于MySQL的学生信息系统。我可以立刻告诉你,根据日期和名称建立一个唯一的ID是获得重复的最快方法。

I suggest you generate the student IDs as a unique Int, just start the count at a high number, so you don't have an ID of 0001 or 1.

我建议您将学生ID生成为唯一的Int,只需以较高的数字开始计数,因此您没有ID为0001或1。

If you need a visually nicer representation of their ID, you can do something like:

如果您需要在视觉上更好地表示其ID,您可以执行以下操作:

[first initial][last name][last 4 of unique ID]

This will give you a more visually pleasing ID, but it will be based off a unique number. So JSmith1234

这将为您提供更加视觉上令人愉悦的ID,但它将基于一个唯一的数字。所以JSmith1234

更多相关文章

  1. PO,Hibernate,VO,struts,spring,hibernate,Jsp,Oracle,mysql,mss
  2. MySql sqlstate代码大全(转载)
  3. 如何更模块化地编写jQuery代码?
  4. [生活娱乐] 从后端室友那学来的代码
  5. js金额数字格式化实现代码(三位加逗号处理保留两位置小数)
  6. Aptana Studio 3 IDE中有运行JavaScript代码的方法吗?
  7. 如何在JavaScript中编写适当的OOP代码?
  8. 高性能JavaScript代码高亮插件
  9. js“DOM事件”之鼠标事件、js的测试方法、js代码的放置位置

随机推荐

  1. Android ScrollView 判断到顶到底,和设置
  2. Android:开发常用的名令集锦
  3. Android Touch事件分发机制学习
  4. Android隐式启动Activity匹配详解:Action,c
  5. Android TextView文字过多,添加滚动条
  6. Windows下载Android全部源码
  7. 解决CardView无点击效果 实现水波纹效果
  8. android sdk setup时呈现:Failed to fetc
  9. Android 源码分析-打电话和发短信
  10. SD卡读写文件 代码学习