fixed bugs in sql scripts