我想为用户在java语言中注册信息时创建一个唯一的id。 [英] I want to create an unique id for user when they register their information in java language.

查看:176
本文介绍了我想为用户在java语言中注册信息时创建一个唯一的id。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为用户在用java语言注册信息时创建一个唯一的ID



我尝试过:



我试图从数据库中获取行号以使它们成为id但问题是当我删除任何特定用户详细信息时。所有现有ID将同时更改。

I want to create an unique id for user when they register their information in java language

What I have tried:

I have tried to get row no from database to make them id but problem is that when i delete any particular user detail.All existing id will be changed simultaneously.

推荐答案

由于您有数据库,因此很容易:使用IDENTITY列:

标识栏 - 维基百科 [ ^ ]

IDENTITY(属性)(Transact-SQL)| Microsoft Docs [ ^ ]

这样,数据库会维护该值并确保每个新行都有不同的数字。
As you have a database, it's easy: use an IDENTITY column:
Identity column - Wikipedia[^]
IDENTITY (Property) (Transact-SQL) | Microsoft Docs[^]
That way, the DB maintains the value and will ensure that each new row has a different number.


Quote:

我试图从数据库中获取行号以使它们成为id但问题是当我删除任何特定的用户细节时。所有现有ID都将同时更改。

I have tried to get row no from database to make them id but problem is that when i delete any particular user detail.All existing id will be changed simultaneously.



您刚刚发现了没人这样做的原因。


唯一的解决方案是拥有一个持有用户ID的字段。

在SQL中,您可以让服务器自动生成Id,并将Id作为主键,确保Id是唯一的。

否则,您需要在某处保存Id计数器。


You have just discovered the reason why nobody do that.

The only solution is to have a field holding the user Id.
In SQL, you can have the Id automatically generated by server, and making the Id a primary key ensure that Id will be unique.
Otherwise, you need to save an Id counter somewhere.


这篇关于我想为用户在java语言中注册信息时创建一个唯一的id。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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