0

In my application i'm used UUID as primary key, its working fine but its length too large it contains 32-bit characters. how to reduce length of UUID.

Here my UUID

49b0143d-fb8f-4e98-b608-45167748cbc4 

Expected UUID

49b0143d or 49b0143d-fb8f-4e98 

1 Answers1

0

Section 3 of RFC4122 provides the formal definition of UUID string representations. It's 36 characters - 32 hex digits + 4 dashes. So that the generated uuid's will always have these many numbers of characters. So what you can do is either take/extract the first/desired part of the uuid, by using methods like substring preg-split, etc...

Basic substring() usage (copied from php docs)

<?php
echo substr('abcdef', 1);     // bcdef
echo substr('abcdef', 1, 3);  // bcd
echo substr('abcdef', 0, 4);  // abcd
echo substr('abcdef', 0, 8);  // abcdef
echo substr('abcdef', -1, 1); // f

and make your primary key the newly generated one

Community
  • 1
  • 1
Shobi
  • 10,374
  • 6
  • 46
  • 82