SQLite provides the auto-increment facility to the user, in which that we increment integer value automatically as per the requirement. When we use this method, there are slightly different types of algorithms used to calculate the auto-increment value. Finally, we can say the value will be incremented by 1 which means it will never decrease. Create a new table with two column names by using the following statement as follows.
In the above example, we use a create table statement to create a new table name as a sample with two attributes such as name and address with text data type as shown in the above statement. The end out of the above statement we illustrated by using the following screenshot. Now insert some records into the sample table by using insert into the statement as follows.
After the insertion operation, we can use a select statement to see the inserted records as follows. Now see another example with a primary key as follows. Create a new table with the primary key constraint as follows. This is a guide to SQLite autoincrement.
Here we discuss the definition, How the SQLite autoincrement function works? SQLite has an interesting way of handling auto-increment columns. By auto-incrementing columns, I mean columns that increment automatically whenever new data is inserted. In this table, the CatId column is an autoincrement column. The way it works is, the NULL is automatically converted into an integer which is one greater than the largest value of that column over all other rows in the table.
If the table is empty, the value will be 1. If the largest value of the column is the largest possible integer , then SQLite will choose an unused key at random. This typically means that it will reuse old keys that were previously deleted.
0コメント