MySQL has auto_increment
which allows us to create unique primary keys automatically.
However, this only works for integer columns. There doesn't seem to be a way to combine auto_increment
with binary
columns, for example:
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.)
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.