Generating a Random and unique(will be stored in DB) 8 digit number

There are lots of python functions that can do this for you which can be found by googling python random function. You can use these directly in Anvil (some functions may be server code only)

As for checking the uniqueness, that seems contradictory to the idea of something being random. If instead you wanted a unique number you should search for that instead.

It is difficult to help you more with this given that there is not a lot to go on.

Might I suggest reading this post about how to ask a good question and then give the community a little more information to help you.