Fix bug in sql script