dsj8000 2011-04-12 21:30
浏览 355

在MySQL中创建短唯一ID的最佳方法

I need to create unique IDs in MySQL for a php application. I what the IDs to be about 7 chars max, the only think i can think of doing is to used the uid that is created but i would like to create a random string rather than just 0000123 etc... i would prefer AB738DD or somthing of the like.

The other thing i thought of was using php to generate an id then check the db to see if it is already there, and if there isnt a match insert with that id, the only problem is i think that will create unneeded load on the mysql server and extra queries.

Has anyone else got any other ideas?

Thanks

  • 写回答

3条回答 默认 最新

  • dtmtu02882 2011-04-12 21:32
    关注

    One solution would be to store an integer but convert the value to hex on display. (Obviously this won't be random, but it wouldn't be all digits either).

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条