mysql unique number generation

前端 未结 9 952
南笙
南笙 2020-12-05 03:17

I want to generate a unique random integer (from 10000 to 99999) identity just by clean mySQL; any ideas?

I don\'t want to generate this number in php by cycling (ge

9条回答
  •  春和景丽
    2020-12-05 03:56

    The only half-way reasonable idea I can come up with is to create a table with a finite pool of IDs and as they are used remove them from that table. Those keys can be unique and a script could be created to generate that table. Then you could pull one of those keys by generating a random select from the available keys. I said 'half-way' reasonable and honestly that was being way to generous, but it beats randomly generating keys until you create a unique one I suppose.

提交回复
热议问题