G
G
Gennady Kruglov2016-06-20 15:51:42
SQL
Gennady Kruglov, 2016-06-20 15:51:42

Are there ways to generate a unique ID for a client, not in UUID or GUID format, but a simple integer?

Are there ways to generate a unique ID for a client, not in UUID or GUID format, but a simple integer?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey, 2016-06-20
@alsopub

INT field with AUTO_INCREMENT in the database.
Most likely it is already there.

W
WarFollowsMe, 2016-06-20
@WarFollowsMe

C# has the ability to create a unique int using System.Threading.Interlocked.Increment.
It looks like this:

private static int tick = Environment.TickCount;
public int Id
{
    get{return Interlocked.Increment(ref tick);}
}

For your specific case, I think it's still worth using the option described in other answers (using auto_increment). But in the general case, if a similar task arises not only within the framework of working with the database, it is useful to know about this possibility.

A
AxisPod, 2016-06-21
@AxisPod

In MSSQL, there is a property of the IDENTITY field, one way or another, if you store it, then you should use it, do the clustered index by UUID, this is killing the database performance. What is wrong with such a field?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question