sql script corrected and tested