在mysql中生成批号? [英] Generate batch number in mysql?

查看:350
本文介绍了在mysql中生成批号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个脚本,其功能应如下:

We have a script that should function like so:

脚本在数据库中插入 n 行,并在 batch 列中插入相同的 unique 号.

Script inserts n rows into database inserting the same unique number into the batch column.

脚本将具有批号的作业放入AWS队列中.
AWS Worker进行一些处理并在我们的服务器上触发另一个脚本.
我们服务器上的脚本会将来自AWS工作程序的响应插入到批处理中的所有行中.

Script puts a job on the AWS queue with the batch number.
AWS worker does some processing and fires off another script on our server.
Script on our server inserts the response from the AWS worker into all rows in the batch.

这很容易,除了-创建批号. 由于多个用户可以同时创建一个批次,因此我们不能只获取最大批次数并添加1.

This is all easy except - creating the batch number. We can't just get the max batch number and add 1 due to multiple users being able to create a batch at the same time.

那么最理想的方法是什么?批号虽然可以使用,但不必为整数.

So what is the most ideal way to do this? The batch number does not have to be an integer although it could be useful.

推荐答案

创建一个名为batches的新表,该表每批具有一行.该表将具有一个称为batchid的自动递增列.

Create a new table called batches that has one row per batch. This table will have an auto-increment column called batchid.

您的脚本将从在此表中插入一行开始.除了batchid,它还可以包含创建批处理的时间,创建批处理的人以及其他相关信息的时间戳.然后,该ID将在批次的其余部分中使用.

Your script will start by inserting a row into this table. In addition to the batchid, it can also contain the time stamp of when the batch was created, who created it, and perhaps other pertinent information. This id will then be used through the rest of the batch.

这篇关于在mysql中生成批号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆