I know it is important for blockchain to constantly checking whether the previous blocks have been altered or not but I don't know why does blockchain needs hash difficulty like zeros at the beginning of the hash value. From my perspective, since the previous blocks cannot be altered, if a database can memorize all the hash value of the previous blocks, once identify a change in those values, we can know which block has been altered due to a cyber attack(maybe). How is hash difficulty playing an important role here, is it necessary to use the method of constantly checking previous blocks' beginning sub string? Rehashing consumes a lot of computing power so I really don't understand why they are doing this. Also besides cryptocurrency, in other implementations for blockchain like food supply chain, do we need this hash difficulty?
"Memorizing" the hashes of previous blocks is not workable, because a new node must be able to start from scratch (with no memory) and validate the previous blocks on its own. It should not have to "trust" other nodes. That is a major design goal of blockchain.
The hash difficulty is necessary to limit the speed at which new blocks can be created worldwide (for example one new block worldwide every 10 minutes). If they could be created very quickly then a malicious node could create an incorrect (but valid looking) chain that is the longest of any other node's. The rule is that the longest chain is accepted.
EDIT:
Just to expand... blockchain design anticipates that occasionally a small number (say, 1 or 2) of malicious blocks could be added to the "longest" chain and would be accepted as valid temporarily. It is expected that the non-malicious majority of hashing power worldwide will eventually come up with an even longer chain that discards the malicious block(s) (performing a co-called "blockchain rewrite").
That is why it is recommended to wait for a certain number of blocks to be added (so-called "confirmations", e.g. 6) before accepting a new block as correct (because it is extremely unlikely to ever be rewritten at that point). It's also why the so-called "51%" attack (meaning the majority of worldwide hashing power is conspiring malliciously) is a vulnerability.