Is there any way to insert the row number of a row as it is inserted in MySQL? Something like:
INSERT INTO users SET uid=ROWNUMBER(), email="joe@example.com";
If not, is there any other way that you would suggest to create a uid based on the entry number?
Thanks!
解决方案
MySQL (along with most RDBMS) does not have any internal row number or order. However, you can create an uid column which will auto increment every time a new record is inserted.
ALTER TABLE users ADD uid INT NOT NULL AUTO_INCREMENT PRIMARY KEY
Now when you do an INSERT, MySQL will automatically increment the uid column.
INSERT INTO users SET email="joe@example.com"