Implemented the last inserted key lookup in sql and tested