Fix sql errors when dropping tables