A wallet.dat
file will contain many, many bitcoin keypairs/addresses. So there is no reason to delete an older address, and in fact this is probably a bad idea. If you or anyone else ever mistakenly sends bitcoins to that address, it will be impossible to recover them once you've deleted those keys.
If you do not have the private key for an address, you will not be able to spend any bitcoin stored at it. That said, you can still import the address as a 'watch-only' address, meaning your wallet will keep track of the address' balance, but not be able to spend the coins (because you don't have the private key).
You can use the following commands:
bitcoin-cli importaddress
for a bitcoin address
bitcoin-cli importpubkey
for a bitcoin public key
Note that in order for your wallet to learn about transactions sent to the imported address/pubkey in the past, your wallet will need to rescan the blockchain (rescan=true
by default when calling importaddress
or importpubkey
). If you happen to know which blocks the relevant transactions were included in, you can set rescan=false
and then run rescanblockchain ("start_height") ("stop_height")
and it will complete the rescan much faster.
And if you do have the private key, you can import it using:
bitcoin-cli importprivkey