I want to automatically create user's, which all have a unique ID.
Now here's the problem. If two users are created at exactly the same nanosecond, it may not cause problems. Thus, what i do now is:
- Get the next Autoincrement number
- Add a new user with the name "U" + autoincrement number + random(0-9)
When more than 10 users are created at the exact same nanosecond, this will still cause problems (in theory!). Thus, I'm looking for a way to let MySQL handle the username.
Consider the following table:
CREATE TABLE IF NOT EXISTS `test` ( `id` int(5) NOT NULL AUTO_INCREMENT, `name` varchar(20) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
I want to use:
INSERT INTO test (id, name) VALUES (null, "U" + id)
where id is the autoincrement number. But, since id is not defined in MySQL, it will contain 0.
How to define id, so that it will contain the autoincrement number of that row. This can easily be done by two queries, but I'm looking to do this in only one query :)