- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Generating a unique random 10 character string using MySQL?
In order to generate a 10 character string, we can use inbuilt functions ‘rand()’ and ‘char()’. The following is the query to generate random 10 character string.
mysql> SELECT concat( - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97) - > )AS Random10CharacterString;
Here is the output showing random 10 character string.
+-------------------------+ | Random10CharacterString | +-------------------------+ | duscikyspy | +-------------------------+ 1 row in set (0.00 sec)
The following is the query to generate random characters in upper case.
mysql> select concat( - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65) - > )AS Random10CharacterString;
The following is the output.
+-------------------------+ | Random10CharacterString | +-------------------------+ | WMWWVOIXPF | +-------------------------+ 1 row in set (0.00 sec)
The above output displays random characters in upper case.
- Related Articles
- Generating Random String Using PHP
- Generating random strings until a given string is generated using Python
- Generating random string with a specific length in JavaScript
- How to find a unique character in a string using java?
- Generating random string of specified length in JavaScript
- First Unique Character in a String in Python
- Generating Random id's using UUID in Python
- Find the index of the first unique character in a given string using C++
- Generating random numbers in Java
- Generating random numbers in C#
- Generating random Id’s in Python
- Generating random number in a range in C
- Generating n random numbers between a range - JavaScript
- Generating random number list in Python
- Generating Random Short Id in Node.js

Advertisements