Improved SQL script for copying data