Auto_ increment is used to increase by 1 while insert a new data to mysql table. The auto increment column must be defined as key. By default auto_increment is start with 1. Suppose you want to auto_increment starts with 'N' values. Then you can change the auto_increment initial value in mysql. IT is possible. First you create table with auto_increment. Then use following mysql query :
Alter table table_name AUTO_INCREMENT=N
Where, N can be any numbers like 100,1000,10000...
Now the table is created with auto increment. If you add any values, then auto_increment starts with 1 in mysql. Consider following example. You add 3 values to mysql table. ie,
insert into table1 values('','sample1','sample1.jpg')
insert into table1 values('','sample3','sample2.jpg')
insert into table1 values('','sample3','sample3.jpg')
Now your table look like this:
You change auto_increment initial value to 100. The mysql query is:
Alter table table_name AUTO_INCREMENT=N
Where, N can be any numbers like 100,1000,10000...
Create table with auto_increment in mysql:
You can add auto_increment while creating new table in mysql. The mysql query is:
CREATE TABLE table1
(No int(5) NOT NULL AUTO_INCREMENT PRIMARY KEY,
Game_name varchar(15), Image varchar(15))
Now the table is created with auto increment. If you add any values, then auto_increment starts with 1 in mysql. Consider following example. You add 3 values to mysql table. ie,
insert into table1 values('','sample1','sample1.jpg')
insert into table1 values('','sample3','sample2.jpg')
insert into table1 values('','sample3','sample3.jpg')
Now your table look like this:
Change auto_increment initial value in mysql:
You change auto_increment initial value to 100. The mysql query is:
Alter table table1 AUTO_INCREMENT=100
Now you insert data to your mysql table. Then it look like this:
Now you can see the row starts with 100. You can changed starting value of auto_increment in mysql
Related Post:
Related Post: