Mysql – Starting Auto Increment Primary Key with your own number
In mysql, we can also define our own number that primary key starts with if it is set as the auto_increment.
Though it sounds as the complex task but its easy to implement.
First create table with one field as primary key and autoincrement attribute set.
CREATE TABLE `tableName` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1
This will create the table on your database with two field ‘id’ as datatype integer and ‘name’ as datatype varchar.Here field ‘id’ acts as the primary key for that particular table with its values auto increment.
By default ‘id’ starts with value 1.
To make it start with our own number , one line of code is enough.
ALTER TABLE TABLENAME AUTO_INCREMENT = 200
Subsequently , new value for our field ‘id’ starts with 200……………..
460 views

