Skip to content

Instantly share code, notes, and snippets.

@kovid-r
Last active September 16, 2020 14:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kovid-r/736bdbd4ad75924fe99b102978525fd6 to your computer and use it in GitHub Desktop.
Save kovid-r/736bdbd4ad75924fe99b102978525fd6 to your computer and use it in GitHub Desktop.
Generate test data using MariaDB/MySQL
with recursive series as (
select 1 as id union all
select id + 1 as id
from series
where id < 100),
cities as (select 'Santa Clara' city union all
select 'Los Angeles' union all
select 'Santa Clarita' union all
select 'San Bernardino' union all
select 'Alameda' union all
select 'San Mateo' union all
select 'Santa Barbara'
),
first_names as (select 'John' first_name union all
select 'James' first_name union all
select 'David' first_name union all
select 'Jeremy' first_name union all
select 'Ron' first_name union all
select 'Katie' first_name union all
select 'Nikita' first_name union all
select 'Rachel' first_name union all
select 'Tom' first_name
),
last_names as (select 'Smith' last_name union all
select 'Johnson' last_name union all
select 'Williams' last_name union all
select 'Brown' last_name union all
select 'Jones' last_name union all
select 'Miller' last_name union all
select 'Davis' last_name union all
select 'Wilson' last_name union all
select 'West' last_name
)
select id, user_id, first_name, last_name
dob, city, salary - mod(salary, 100) salary
from (select id,
substring(md5(rand()),1,20) user_id,
(select first_name from first_names order by rand() limit 1) first_name,
(select last_name from last_names order by rand() limit 1) last_name,
date(concat_ws('-',(floor(1919+rand()*100)),
(floor(1+rand()*12)),
(floor(1+rand()*28))
)
) dob,
(select city from cities order by rand() limit 1) city,
floor((rand() * (120000 + 1)) + 35000) salary
from series) as t;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment