如何为每个用户生成唯一的ID? [英] how to generate unique id per user?

查看:63
本文介绍了如何为每个用户生成唯一的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Default.aspx网页,该网页将为每个新用户生成ID,然后在单击Default.aspx ...时将ID提交给数据库.

I have a webpage Default.aspx which generate the id for each new user after that the id will be subbmitted to database on button click on Default.aspx...

如果另一个用户也输入了相同的时间,则ID将相同...直到他们按下default.aspx上的按钮

if onother user is also entering the same time the id will be the same ... till they press button on default.aspx

如何摆脱这个问题...以便...向每个用户分配唯一的ID ...

How to get rid of this issue...so that ... each user will be alloted the unique id ...

我使用读写代码生成唯一ID.

i m using the read write code to generate unique id ..

推荐答案

您可以生成一个Guid:

You could generate a Guid:

Guid.NewGuid()

或者您可以让数据库在插入时为您生成它.一种方法是通过序列.有关代理键

Or you could let the database generate it for you upon insert. One way to do this is via a Sequence. See the wikipedia article for Surrogate Keys

摘自文章:

数据库中的代理密钥是建模世界中的实体或数据库中的对象的唯一标识符.代理密钥不是从应用程序数据派生的.

A surrogate key in a database is a unique identifier for either an entity in the modeled world or an object in the database. The surrogate key is not derived from application data.

序列/自动递增的列"选项将变得更简单,并且在手动查询数据库时(在调试过程中)更容易记住,但是我工作的DBA表示,通过切换到Guid,他的性能提高了20%.他当时使用的是Oracle,但是他的数据库很大,:)

The Sequence/auto-incremented column option is going to be simpler, and easier to remember when manually querying your DB (during debugging), but the DBA at my work says he's gotten 20% increases in performance by switching to Guids. He was using Oracle, and his database was huge, though :)

这篇关于如何为每个用户生成唯一的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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