It sounds like maybe your reaching a webserver timeout. Since you are running under CGI, is it possible for you to run the altertable script via the command line? That should allow you to bypass any webserver timeouts.