Fixing SQL script