I am new to MySQL and I am having an issue with unique identifier token. Here is my employee table.
Employee Table (MySQL)
CREATE TABLE employees (
emp_no INT NOT NULL, -- AUTO_INCREMENT
first_name VARCHAR(14) NOT NULL,
last_name VARCHAR(16) NOT NULL,
hire_date DATE NOT NULL,
token varchar(100) not null,
PRIMARY KEY (emp_no)
);
I have employee table in MySQL. emp_no is the primary key with auto-increment. I want to have a token for each employee and the token should be unique for each employee.
The token should look something like:
32f41e07b9e8393ae250ad617801a155
How can I achieve this?
My Approach
SELECT SUBSTRING(MD5(RAND()) FROM 1 FOR 16) AS myrandomstring
But I don't think that the above query will guarantee uniqueness for each employee.