How can I make it so when an entry is created in a table, one of the columns unique_id
automatically gets filled with a randomly generated integer? Can this be done straight from mysql? I've seen that you can automatically fill it with a timestamp and such, so is it possible to automatically fill it with a randomly generated integer?
创建条目时,在列中生成随机且唯一的ID
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答
- dongyuan2388 2013-11-20 06:15关注
you can try this
SELECT FLOOR(10000 + RAND() * 89999) AS my_random_number FROM mytable WHERE "my_random_number" NOT IN (SELECT id FROM mytable) LIMIT 1
OR SImply this
SELECT FLOOR(RAND() * 1000000);
解决 无用评论 打赏 举报
悬赏问题
- ¥15 js调用html页面需要隐藏某个按钮
- ¥15 ads仿真结果在圆图上是怎么读数的
- ¥20 Cotex M3的调试和程序执行方式是什么样的?
- ¥20 java项目连接sqlserver时报ssl相关错误
- ¥15 一道python难题3
- ¥15 牛顿斯科特系数表表示
- ¥15 arduino 步进电机
- ¥20 程序进入HardFault_Handler
- ¥15 关于#python#的问题:自动化测试
- ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题