Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I start auto increment from a specific point?

Tags:

sql

mysql

CREATE TABLE `batchinfo` (   `rowid` int(11) NOT NULL AUTO_INCREMENT,   `datapath` mediumtext,   `analysistime` varchar(50) DEFAULT NULL,   `reporttime` varchar(50) DEFAULT NULL,   `lastcalib` varchar(50) DEFAULT NULL,   `analystname` varchar(150) DEFAULT NULL,   `reportname` varchar(150) DEFAULT NULL,   `batchstate` varchar(150) DEFAULT NULL,   `instrument` varchar(20) DEFAULT NULL,   PRIMARY KEY (`rowid`),   UNIQUE KEY `rowid_UNIQUE` (`rowid`) ) ENGINE=InnoDB AUTO_INCREMENT=15034 DEFAULT CHARSET=latin1 

I want to start the auto incremenet from 20000.

How do I do that? Can I edit the table some how to start incrementing from 20000?

like image 417
Alex Gordon Avatar asked Aug 12 '10 17:08

Alex Gordon


People also ask

Can you set auto increment?

Auto-increment allows a unique number to be generated automatically when a new record is inserted into a table. Often this is the primary key field that we would like to be created automatically every time a new record is inserted.

How do I add an auto increment to an existing column?

To change the value of the AUTO_INCREMENT the table must be using the MyISAM engine. So go to the table properties, change the engine from say InnoDB to MyISAM, then change the AUTO_INCREMENT value to whatever should be next in your sequence.

How do I change my primary key to auto increment?

To change a primary key to auto_increment, you can use MODIFY command. Let us first create a table. Look at the above sample output, StudentId column has been changed to auto_increment.


1 Answers

ALTER TABLE batchinfo AUTO_INCREMENT = 20000; 

See also Autoincrement

like image 66
stacker Avatar answered Sep 29 '22 09:09

stacker