Sample Header Ad - 728x90

How can I create a unique and random alphanumeric string using MySQL's Default Value? (v 5.6)

1 vote
1 answer
4070 views
I am building a MySQL database and think using implicit DEFAULTS seems very promising. I am successfully using DEFAULT CURRENT_TIMESTAMP and DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP for on insert timestamps and on update timestamps. I would like to add a default for a public key. A 32 character unique and random alphanumeric string. Is this possible using the DEFAULT field specification? If so, how? Or must I handle this by creating a random value and checking it's uniqueness, *for the 1 in 1.5^50 chance it's a duplicate*, on INSERT? This article seemed promising, but didn't give me an definitive answers: https://www.percona.com/blog/2015/04/29/generated-virtual-columns-in-mysql-5-7-labs/ Thank you in advance
Asked by LWSChad (111 rep)
Jun 29, 2019, 04:13 AM
Last activity: Apr 20, 2025, 10:01 PM