getting codes from my db is not working. Any advice?

I’m trying to add the unique code (simply listed as 1,2,34…) to my subscription orders. I want to be able to download customers and see this code listed with the order on download. I also want the code to go on the thank you page of the subscription customer.

my end goal is to assign a 8-digit alpha numeric code to each customer, but the codes need to come from my file (which in testing is listed as DB codes and rows 1-7). I do not want to repeat any row.

I have tried a couple days without success and would value any input.

Thank you