Check out example codes for "generate random & unique mysql string". It will help you in understanding the concepts better.

Code Example 1

DO 
    SELECT LEFT(UUID(), 8) INTO @var;
    INSERT INTO col (@var);
WHILE there_is_a_unique_constraint_violation

Learn ReactJs, React Native from akashmittal.com