How to auto-increment last digits in SQL?

I make a site and provide each user with a unique identifier after registration. The unique identifier should start with 80001. But now I want the second user to have identifier 80002, the third user to 80003. Could this be possible in SQL, because I only want to update only the last 3 digits. I tried to do this through the sequence, but could not do it.

+4
source share
2 answers

The way to do this is:

ALTER TABLE tbl AUTO_INCREMENT = 80000;

, . -, , , . -, 999 , , . -, , . . , , .

:

ALTER tbl MODIFY `rowid` int(11) NOT NULL AUTO_INCREMENT;

:

UPDATE tbl SET `rowid` = `rowid`-80000;
+5

ALTER TABLE student AUTO_INCREMENT=80000;

,

CREATE TABLE `student ` (
  `rowid` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`rowid`),
  UNIQUE KEY `rowid_UNIQUE` (`rowid`)
) ENGINE=InnoDB AUTO_INCREMENT=80000 DEFAULT CHARSET=latin1;
+2

Source: https://habr.com/ru/post/1533464/


All Articles