fix the sql errors in deletion