Generatore nomi casuale in MySql

It often happens to prepare demo for customers with a fully populated database. The preparation of vanilla db frequently start from an old production archive where you must change first and last names of real customers. These sql procedures help us to solve the problem. Random generation of italian first names:

1
2
3
4
DROP FUNCTION IF EXISTS generate_fst_name_it;
DELIMITER $$ CREATE FUNCTION generate_fst_name_it ()
RETURNS VARCHAR(255) BEGIN RETURN ELT(FLOOR(1 + (RAND() * (100-1))), "FRANCESCO","ALESSANDRO","ANDREA","LORENZO","MATTEO","GABRIELE","MATTIA","LEONARDO","DAVIDE","RICCARDO","FEDERICO","LUCA","GIUSEPPE","MARCO","TOMMASO","ANTONIO","SIMONE","SAMUELE","GIOVANNI","PIETRO","CHRISTIAN","ALESSIO","EDOARDO","DIEGO","FILIPPO","EMANUELE","DANIELE","MICHELE","CRISTIAN","SOFIA","GIULIA","MARTINA","GIORGIA","SARA","EMMA","DEBORA","AURORA","CHIARA","ALICE","ALESSIA","GAIA","ANNA","FRANCESCA","NOEMI","VIOLA","GRETA","ELISA","MATILDE","GIADA","ELENA","GINEVRA","BEATRICE","VITTORIA","NICOLE","ARIANNA","MARTA","ANGELICA","ASIA","LUDOVICA","GIULIO","MARIO","FABIO","ROBERTA","ROBERTO","STEFANO","GIORGIO","PINO","SONIA","MARINA","MARIA","MARA","INES","CARLO","FEDERICA","PAOLA","PAOLO","LUCIA","LUCIO","ELEONORA","NICOLA","ATTILIO","BARBARA","DANIELA","PATRIZIO","PATRIZIA", "PIERO","PIERA","ANTONIO","SABRINA","LARA","SERENA","LUIGI","GAETANO","ARGENTINO","LORENA","GIULIANO","BRUNO","BRUNA","AZZURRA","FELICE");
END$$ DELIMITER ;

Random generation of italian last names:

1
2
3
DROP FUNCTION IF EXISTS generate_lst_name_it;
DELIMITER $$ CREATE FUNCTION generate_lst_name_it () RETURNS VARCHAR(255) BEGIN RETURN ELT(FLOOR(1 + (RAND() * (100-1))), "ROSSI","RUSSO","FERRARI","ESPOSITO","BIANCHI","ROMANO","COLOMBO","RICCI","MARINO","GRECO","BRUNO","GALLO","CONTI","DE LUCA","MANCINI","COSTA","GIORDANO","RIZZO","LOMBARDI","MORETTI","BARBIERI","FONTANA","SANTORO","MARIANI","RINALDI","CARUSO","FERRARA","GALLI","MARTINI","LEONE","LONGO","GENTILE","MARTINELLI","VITALE","LOMBARDO","SERRA","COPPOLA","DE SANTIS","ISERNIA","MARCHETTI","PARISI","VILLA","CONTE","FERRARO","FERRI","FABBRI","BIANCO","MARINI","GRASSO","VALENTINI","MESSINA","SALA","DE ANGELIS","GATTI","PELLEGRINI","PALUMBO","SANNA","FARINA","RIZZI","MONTI","CATTANEO","MORELLI","AMATO","SILVESTRI","MAZZA","TESTA","GRASSI","PELLEGRINO","CARBONE","GIULIANI","BENEDETTI","BARONE","ROSSETTI","CAPUTO","MONTANARI","GUERRA","PALMIERI","BERNARDI","MARTINO","FIORE","DE ROSA","FERRETTI","BELLINI","BASILE","RIVA","DONATI","PIRAS","VITALI","BATTAGLIA","SARTORI","NERI","COSTANTINI","MILANI","PAGANO","RUGGIERO","SORRENTINO","TOTTI","ORLANDO","PLAPPLA","NEGRI");
END$$ DELIMITER ;

Random generation of english first names:

1
2
3
4
5
DROP FUNCTION IF EXISTS generate_fst_name_en;
DELIMITER $$
CREATE FUNCTION generate_fst_name_en ()
RETURNS VARCHAR(255) BEGIN RETURN ELT(FLOOR(1 + (RAND() * (100-1))), "SOPHIA","ISABELLA","EMMA","OLIVIA","AVA","EMILY","ABIGAIL","MADISON","MIA","CHLOE","ELIZABETH","ELLA","ADDISON","NATALIE","LILY","GRACE","SAMANTHA","AVERY","SOFIA","AUBREY","BROOKLYN","LILLIAN","VICTORIA","EVELYN","HANNAH","ALEXIS","CHARLOTTE","ZOEY","LEAH","AMELIA","ZOE","HAILEY","LAYLA","GABRIELLA","NEVAEH","KAYLEE","ALYSSA","ANNA","SARAH","ALLISON","SAVANNAH","ASHLEY","AUDREY","TAYLOR","BRIANNA","AALIYAH","RILEY","CAMILA","KHLOE","CLAIRE","SOPHIE","ARIANNA","JACOB","MASON","WILLIAM","JAYDEN","NOAH","MICHAEL","ETHAN","ALEXANDER","AIDEN","DANIEL","ANTHONY","MATTHEW","ELIJAH","JOSHUA","LIAM","ANDREW","JAMES","DAVID","BENJAMIN","LOGAN","CHRISTOPHER","JOSEPH","JACKSON","GABRIEL","RYAN","SAMUEL","JOHN","NATHAN","LUCAS","CHRISTIAN","JONATHAN","CALEB","DYLAN","LANDON","ISAAC","GAVIN","BRAYDEN","TYLER","LUKE","EVAN","CARTER","NICHOLAS","ISAIAH","OWEN","JACK","JORDAN","BRANDON","WYATT");
END$$ DELIMITER ;

Random generation of english last names:

1
2
3
4
DROP FUNCTION IF EXISTS generate_lst_name_en;
DELIMITER $$ CREATE FUNCTION generate_lst_name_en ()
RETURNS VARCHAR(255) BEGIN RETURN ELT(FLOOR(1 + (RAND() * (100-1))), "SMITH","JOHNSON","WILLIAMS","JONES","BROWN","DAVIS","MILLER","WILSON","MOORE","TAYLOR","ANDERSON","THOMAS","JACKSON","WHITE","HARRIS","MARTIN","THOMPSON","GARCIA","MARTINEZ","ROBINSON","CLARK","RODRIGUEZ","LEWIS","LEE","WALKER","HALL","ALLEN","YOUNG","HERNANDEZ","KING","WRIGHT","LOPEZ","HILL","SCOTT","GREEN","ADAMS","BAKER","GONZALEZ","NELSON","CARTER","MITCHELL","PEREZ","ROBERTS","TURNER","PHILLIPS","CAMPBELL","PARKER","EVANS","EDWARDS","COLLINS","STEWART","SANCHEZ","MORRIS","ROGERS","REED","COOK","MORGAN","BELL","MURPHY","BAILEY","RIVERA","COOPER","RICHARDSON","COX","HOWARD","WARD","TORRES","PETERSON","GRAY","RAMIREZ","JAMES","WATSON","BROOKS","KELLY","SANDERS","PRICE","BENNETT","WOOD","BARNES","ROSS","HENDERSON","COLEMAN","JENKINS","PERRY","POWELL","LONG","PATTERSON","HUGHES","FLORES","WASHINGTON","BUTLER","SIMMONS","FOSTER","GONZALES","BRYANT","ALEXANDER","RUSSELL","GRIFFIN","DIAZ","HAYES");
END$$ DELIMITER ;

test

1
2
SELECT generate_fst_name_it() AS FirstName, generate_lst_name_it() AS LastName;
SELECT generate_fst_name_en() AS FirstName, generate_lst_name_en() AS LastName;

Enjoy!

giulio isernia

View more posts from this author