T
T
trytrytry2014-11-22 23:03:55
Database design
trytrytry, 2014-11-22 23:03:55

How to create a unique id without using a sequence?

the only thing I came up with is to find the maximum value of the column and add one to it. Could you suggest any other ways? (they may not be effective)

Answer the question

In order to leave comments, you need to log in

5 answer(s)
H
HellBit, 2014-11-22
@HellBit

When creating, use the current date.

T
trytrytry, 2014-11-22
@trytrytry

what if the id is just a number?

W
WDev, 2014-11-22
@WDev

You don't have to think of anything. GUID (UUID). Look at the wiki. This is the standard. There are also calculation functions for different languages.

S
Sergey Savostin, 2014-11-22
@savostin

Could you clarify the end goal.
If you need to constantly generate, then GUID or UUID, as advised above.
If, say, you need to generate a finite number of identifiers, then go to random.org and row with a shovel.
If, as you say, only numbers, and constantly generate, and even SQL, as you indicated, then I see no other way how to do random and check to exhaustion whether there was already one in the database. Well, or take in advance N, or better M numbers from random.org and insert one from there into the database. I really don't know what will happen when they end ;)

G
Geny, 2014-11-24
@Geny

the only thing I came up with is to find the maximum value of the column and add one to it. Could you suggest any other ways? (they may not be effective)

Without select ... for update - it's not safe, it's not efficient with it ...,))
you can try timestamp .. if you need a number, then do something like this
select to_number(TO_CHAR(current_timestamp, 'SSSSSSSSSSSS')) from dual is more efficient than select ... for update

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question