#! /usr/bin/perl -w

use strict;

my $count = shift;
$count ||= 10;

$count = 99 if $count > 99;

my $parent = "b00";
my @kids = map { sprintf "b%02d", $_ } 1 .. 100;

foreach my $t (@kids, $parent) { print "DROP TABLE IF EXISTS $t;\n"; }

print <<EOF;
create table $parent (
    id int unsigned not null auto_increment primary key
) engine = innodb;
EOF

foreach my $t (@kids[0 .. $count - 1]) {
    print <<EOF;

create table $t (
    fk int unsigned not null,
    index (fk),
    foreign key (fk) references $parent (id)
        on update cascade on delete restrict
) engine = innodb;
EOF
}

print "show tables like 'b_%';\n";

exit 0;
