Advertisement
Guest User

Duplicate Listing

a guest
Feb 7th, 2013
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. drop table usr;
  2. drop table team;
  3.  
  4. create table usr (
  5.     usr_id int,
  6.     usr_firstname varchar(50),
  7.     usr_lastname varchar(50),
  8.     usr_jobtitle varchar(50),
  9.     usr_department varchar(50),
  10.     usr_email varchar(50),
  11.     match_firstname int,
  12.     match_lastname int,
  13.     match_jobtitle int,
  14.     match_department int,
  15.     match_email int,
  16.     team_id int,
  17.     primary key(usr_id)
  18. );
  19. create index ixusr_firstname on usr(usr_firstname);
  20. create index ixusr_lastname on usr(usr_lastname);
  21. create index ixusr_jobtitle on usr(usr_jobtitle);
  22. create index ixusr_department on usr(usr_department);
  23. create index ixusr_email on usr(usr_email);
  24.  
  25. create table team (
  26.     team_id int,
  27.     team_name varchar(50),
  28.     team_streetno varchar(50),
  29.     team_city varchar(50),
  30.     match_team_name int,
  31.     match_team_streetno int,
  32.     match_team_city int,
  33.     primary key(team_id)
  34. );
  35. create index ixteam_name on team(team_name);
  36. create index ixteam_streetno on team(team_streetno);
  37. create index ixteam_city on team(team_city);
  38.  
  39. delete from usr;
  40.  
  41. with recursive q(A) as (
  42.     select 1
  43.     union all
  44.     select A+1
  45.     from q
  46.     where A < 70000
  47. ), rnd as (
  48.     select ARRAY['John','Jim','Bob','Charles','Tom','Jane','Jill','Betty','Helen','Courtney'] vals
  49.     --select ARRAY['John','Charles','Jill'] vals
  50. )
  51. insert into usr (usr_id, usr_firstname, usr_lastname, usr_jobtitle, usr_department, usr_email)
  52. select row_number() over (order by 1),
  53.        vals[1+floor(random()*6)],
  54.        vals[1+floor(random()*6)],
  55.        vals[1+floor(random()*6)],
  56.        vals[1+floor(random()*6)],
  57.        vals[1+floor(random()*6)]
  58. from q, rnd;
  59.  
  60. update usr set
  61.     match_firstname = ascii(usr_firstname)*10000 + ascii(substring(usr_firstname from 3))*100 + ascii(substring(usr_firstname from 4)),
  62.     match_lastname = ascii(usr_lastname)*10000 + ascii(substring(usr_lastname from 3))*100 + ascii(substring(usr_lastname from 4)),
  63.     match_jobtitle = ascii(usr_jobtitle)*10000 + ascii(substring(usr_jobtitle from 3))*100 + ascii(substring(usr_jobtitle from 4)),
  64.     match_department = ascii(usr_department)*10000 + ascii(substring(usr_department from 3))*100 + ascii(substring(usr_department from 4)),
  65.     match_email = ascii(usr_email)*10000 + ascii(substring(usr_email from 3))*100 + ascii(substring(usr_email from 4)),
  66.     team_id = mod(usr_id, 50) + 1;
  67.  
  68. delete from team;
  69.  
  70. with recursive q(A) as (
  71.     select 1
  72.     union all
  73.     select A+1
  74.     from q
  75.     where A < 50
  76. ), rnd as (
  77.     select ARRAY['Alpha','Beta','Gamma','Delta','Epsilon'] vals
  78. )
  79. insert into team (team_id, team_name, team_streetno, team_city)
  80. select row_number() over (order by 1),
  81.        vals[1+floor(random()*5)],
  82.        vals[1+floor(random()*5)],
  83.        vals[1+floor(random()*5)]
  84. from q, rnd;
  85.  
  86. update team set
  87.     match_team_name = ascii(team_name)*10000 + ascii(substring(team_name from 3))*100 + ascii(substring(team_name from 4)),
  88.     match_team_streetno = ascii(team_streetno)*10000 + ascii(substring(team_streetno from 3))*100 + ascii(substring(team_streetno from 4)),
  89.     match_team_city = ascii(team_city)*10000 + ascii(substring(team_city from 3))*100 + ascii(substring(team_city from 4));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement