I have seen other similar questions on SO but what I am asking here is not answered there.
I have a field called GUID on my table that is a primary key.
I want this field to be populated with a random UUID every time a recorded is inserted.
So, I have created this table:
CREATE TABLE `myTable` (
`id` int(6) NOT NULL,
`first_name` varchar(64) NOT NULL,
`last_name` varchar(64) NOT NULL,
`GUID` char(40) NOT NULL,
PRIMARY KEY(`GUID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
DELIMITER //
CREATE TRIGGER `t_GUID` BEFORE INSERT ON `myTable`
FOR EACH ROW begin
SET new.GUID := (SELECT uuid());
END //
DELIMITER ;
I have inserted 4 new records to this table and these are the UUIDs added to the entries:
- ae353781-9022-11ea-b775-1866daed31d4
- ae353a23-9022-11ea-b775-1866daed31d4
- ae353b4e-9022-11ea-b775-1866daed31d4
- ae353c26-9022-11ea-b775-1866daed31d4
except for 3 digits these are basically the same UUID.
How do I generate completely different UUIDs that are unique for the table as new records are being inserted?