在我的 SQL 中自动增加一个带有连接值的列

问题描述

我有一张表,其中有一列名为 wo_number,它基本上是一个从时间戳列自动生成的字符串值。这种类型给出了一个唯一的值(因为它考虑了秒数并且我的应用程序不允许多次插入);问题是,我想在一秒钟内扩展多个插入。因此,如果两个插入同时出现,我想通过自动增量使其 100% 唯一。

wo_number 列值如下所示: WO-071821145515

我希望它看起来像这样: WO-071821145515 - 1

我的表查询是:

[create table work_orders (
id int auto_increment PRIMARY KEY,time_stamp TIMESTAMP DEFAULT Now(),descreption text,requested_by varchar(100),urgent BOOLEAN,assigned_to varchar(100),completion_date TIMESTAMP -- DEFAULT Now(),ack_date timestamp -- DEFAULT Now(),wo_number varchar(100) as (concat('WO-',replace(DATE_FORMAT(time_stamp,"%m%d%y%T"),':',''))),remarks text,machine_id int,department_id int,employee_id int,foreign key (machine_id) REFERENCES machines(id),foreign key (department_id) REFERENCES departments(id),foreign key (employee_id) REFERENCES employees(id)
);

a simple select query

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)