Like randomly generate the record ID in the database?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
85 views
Hello.
I have a table, it has a field ID with auto-increment.
But task is already a friend when adding a new record to this table you need instead of autoincrement to generate 6-digit random number. Need advice with the correct implementation of such tasks.
Thank you.
by | 85 views

4 Answers

0 like 0 dislike
Use UUID (approx. 6ccd780c-baba-1026-9564-5b8c656024db) or UUID_SHORT (approx. 92395783831158784)
But as said earlier, shestiznak, is very small.

For postgresql there are others great features.
by
0 like 0 dislike
by
0 like 0 dislike
6-digit random number in a primary key? This is only enough for a small table.

If satisfied, then do not use PHP rand(), its results are insufficiently random, and replays will start faster, use random_int().

For a truly random key id with high capacity use UUID https://ru.wikipedia.org/wiki/UUID
by
0 like 0 dislike
PHP - rand() and the SQL RAND()
by

Related questions

110,608 questions
257,186 answers
0 comments
35,392 users