use a transaction, delete previous record if there was one where key is equal to the key given.