[英]MySQL alternatives to binary auto-increment column?
MySQL has auto_increment
which allows us to create unique primary keys automatically. MySQL具有auto_increment
,它使我们能够自动创建唯一的主键。
However, this only works for integer columns. 但是,这仅适用于整数列。 There doesn't seem to be a way to combine auto_increment
with binary
columns, for example: 似乎没有办法将auto_increment
与binary
列结合起来,例如:
mysql > create table Users(Id binary(6) auto_increment, primary key(id));
#1063 - Incorrect column specifier for column 'Id'
How can we create or implement an auto-increment binary column? 我们如何创建或实现自动增量二进制列?
(Finding a solution which maintains atomicity and have comparable performance to auto_increment
integer columns.) (找到一种解决方案,该解决方案可以保持原子性并具有与auto_increment
整数列相当的性能。)
A trigger that is called before each insert operation should be safe for transactions and will accomplish what you want. 在每个插入操作之前调用的触发器应该对事务安全,并且可以完成您想要的操作。
Checkout the manual page on triggers. 查阅有关触发器的手册页 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.