rearrange sql contents into another file