sqlite autoincrement is a keyword used for auto incrementing a value of a field in the table. we can auto increment a field value by using autoincrement keyword when creating a table with specific column name to auto increment.
the keyword autoincrement can be used with integer field only.
syntax
the basic usage of autoincrement keyword is as follows −
create table table_name( column1 integer autoincrement, column2 datatype, column3 datatype, ..... columnn datatype, );
example
consider company table to be created as follows −
sqlite> create table company( id integer primary key autoincrement, name text not null, age int not null, address char(50), salary real );
now, insert the following records into table company −
insert into company (name,age,address,salary)
values ( 'paul', 32, 'california', 20000.00 );
insert into company (name,age,address,salary)
values ('allen', 25, 'texas', 15000.00 );
insert into company (name,age,address,salary)
values ('teddy', 23, 'norway', 20000.00 );
insert into company (name,age,address,salary)
values ( 'mark', 25, 'rich-mond ', 65000.00 );
insert into company (name,age,address,salary)
values ( 'david', 27, 'texas', 85000.00 );
insert into company (name,age,address,salary)
values ( 'kim', 22, 'south-hall', 45000.00 );
insert into company (name,age,address,salary)
values ( 'james', 24, 'houston', 10000.00 );
this will insert 7 tuples into the table company and company will have the following records −
id name age address salary ---------- ---------- ---------- ---------- ---------- 1 paul 32 california 20000.0 2 allen 25 texas 15000.0 3 teddy 23 norway 20000.0 4 mark 25 rich-mond 65000.0 5 david 27 texas 85000.0 6 kim 22 south-hall 45000.0 7 james 24 houston 10000.0