Terminate SQL commands properly