SQLite is a serverless database engine written in c programming language. It is one of the most used database engines in our everyday life like Mobile Phones, TV, and so on, etc.
In this article, we will be learning about autoincrement in SQLite, its functionality, and how it works along with the examples and we will also be covering without autoincrement too.
SQLite AUTOINCREMENT
AUTOINCREMENT keyword is used to increase the value of the field automatically. We need to use the autoincrement keyword to increase the field(column) value and it only works for the INTEGER fields. Autoincrement is used only with the columns that act as the primary keys because we use it only for the employee_id, and student_id i.e. for the id's and roll numbers that have sequential numbers as their values for the fields. This primary key acts as a foreign key for the other table.
Syntax:
CREATE TABLE table_name(
column1 INTEGER AUTOINCREMENT,
column2 datatype,
column3 datatype,
.....
columnN datatype,
);
Example: SQLite without Autoincrement
SQLite without AUTOINCREMENT
By the heading itself, you can understand what keyword to use when there is no autoincrement keyword specified. For that, there is a default keyword for autoincrement i.e. ROWID which is not to be specified while creating the table. It is generated automatically and the column is not visible if you do not fetch the data by specifying that column. Now, let us learn about the Rowid.
Introduction to SQLite ROWID Table
Rowid is generated automatically without specifying the keyword. It also works the same as the autoincrement but the small difference is that you need to use the autoincrement keyword to increase the values of the column, whereas there is no need to use the rowid keyword to increase the value of the column as it is default keyword.
In simple words it is the implict auto-increment column i.e rowid.
let us use the products table that has three columns: prod_Id, prod_name and prod_price:
Create Products Table
let us create a products table by adding the fields like prod_Id, prod_name, prod_price and the datatypes are allocated according to their fields and create is the main keyword for creating the table.
CREATE TABLE products (
prod_Id INTEGER,
prod_name TEXT,
prod_price INTEGER
);
The products table created and now let us insert the data into it.
Inserting the Data into Products Table
The table created and now it’s time to insert the data into the table and we are inserting three recods and the text is written in single quotes as they are to be considered as text:
INSERT INTO products(prod_name, prod_price)
values('pens', 100),
('pencils', 50),
('books', 200);
And now 3 records are added into the products table and the data is inserted according to their fields. Let us fetch the data by suing the select statement as below.
Using Select Statement to Fetch the Data
select statement is used to fetch the data from the the table. Here we are going to retrieve all the data from the products table by using the syntax.
SELECT * from products;
products table
As you can see that the prod_Id column has null values because we have not inserted the data.
Fetching the Rowid Column
Here you need to remember one point that rowid will not be visible until and unless you select the rowid column to fetch. Along with rowid we are also fetching the Id column too because you can get the clear knowledge on it.
you can see that the rowid is generated automatically in the below output that means we have not generated the field i.e rowid in our faculty table as you can see above in the create syntax.

Example: SQLite AUTOINCREMENT
For understanding of AUTOINCREMENT concepts in more deeply, we need a table on which we will perform the operations. Let's create a table called faculty which consist Id, name, salary, dept as Columns. Since AUTOINCREMENT keyword works only on the columns which INTEGER values in it. Here all the columns are of INTEGER data types and we make Id column as a PRIMARY KEY.
Let us use the customers table to know more about the SQLite Autoincrement. For this first let us create customers table by using below syntax.
Creating the Customers Table
CREATE TABLE "customers" (
"cust_Id" INTEGER,
"cust_name" TEXT,
"cust_address" TEXT,
PRIMARY KEY("cust_Id" AUTOINCREMENT)
);
The customers table consists of three columns, they are cust_Id, cust_name and cust_address and the datatypes are given according to their fields and the customers table is created.
Insert the Data into the Customers Table
Let us try to insert the data into the customers table by using the insert statement as shown below. You can see that we have not inserted the data into the cust_Id field as it is autoincrement field.
INSERT INTO customers(cust_name, cust_address)
values ( 'Jim', 'California'),
('Rose', 'New York'),
('Mark', 'Texas'),
('David', 'Houston');
Now we have inserted the four records into the customers table and now let us try to fetch the data using the select statement. Now let us see whether the cust_Id field is autoincremented or not?
Fetching the Data Using Select Statement
Now let us use the Select statement to fetch the data.
customers table
As you can see that customers table is fetched with the three columns and they are cust_Id, cust_name and cust_address along with the data inserted inside the table and you can also observe that cust_Id column is autoincremented.
Conclusion
So, the main usage of autoincrement is not to use the repeated values and to use unique values for the rows. Autoincrement key is used with the primary key only that means for the columns that are to be incemented in the sequential order. Coming to the Rowid it is the Default keyword, that need not be specified while creating the table but, if you want to see it in the output you need to use thr Rowid keyword in the select table to fetch it.
Similar Reads
Python OpenCV - imencode() Function
Python OpenCV imencode() function converts (encodes) image formats into streaming data and stores it in-memory cache. It is mostly used to compress image data formats in order to make network transfer easier. Basic example of imencode() FunctionExample 1: We began by importing the necessary librarie
2 min read
Image Compression in Android
In any application, images play a critical role. It aids in the better communication of our message. It does, however, have significant drawbacks. It expands the APK's size. You may have noticed that programs that deal with photos (whether local or downloaded from the internet) are larger in size, a
8 min read
Image Feature Extraction Using Python
An essential method in computer vision and image processing is picture feature extraction. It entails locating and removing different characteristics or patterns from an image in order to make analysis and comprehension easier. These characteristics, which are essential for tasks like object detecti
9 min read
Concept of Mask
A mask is a digital image that is used to hide or reveal portions of another image. In computer graphics, masks are used to create special effects or to select regions of an image for editing. Masks can be created from scratch in an image editor, or they can be generated from existing images. For ex
6 min read
OpenCV Panorama Stitching
This article describes how to "stitch" images using OpenCV and python. Panorama is basically a photograph stretched horizontally without distortion. We will stitch 3 images together in today's discussion to create our own panorama. To achieve this, the images must have some common key-points between
4 min read
Computer Vision Algorithms
Computer vision seeks to mimic the human visual system, enabling computers to see, observe, and understand the world through digital images and videos. This capability is not just about capturing visual data. Still, it involves interpreting and making decisions based on that data, opening up myriad
14 min read
Image Arithmetic in R
Image arithmetic in R Programming Language involves manipulating images by performing mathematical operations on their pixel values. This can be useful for tasks like blending images, adjusting contrast, and creating special effects. In this article, we will see how image arithmetic is implemented i
5 min read
Angular PrimeNG Image Component
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. It provides a lot of templates, components, theme design, an extensive icon library, and much more.
4 min read
Feature detection and matching with OpenCV-Python
In this article, we are going to see about feature detection in computer vision with OpenCV in Python. Feature detection is the process of checking the important features of the image in this case features of the image can be edges, corners, ridges, and blobs in the images. In OpenCV, there are a nu
5 min read
Binary Image
Digital image processing makes the use of algorithms that help us to extract essential features from the images. The aim of the digital image processing is to enhance image quality so that we can extract useful information which can be used later for further detailed studies. Pixel is the smallest u
7 min read
Python Pillow - Colors on an Image
In this article, we will learn Colors on an Image using the Pillow module in Python. Let's discuss some concepts: A crucial class within the Python Imaging Library is the Image class. It's defined within the Image module and provides a PIL image on which manipulation operations are often administere
4 min read
Types of Convolution Kernels
Convolution kernels, or filters, are small matrices used in image processing. They slide over images to apply operations like blurring, sharpening, and edge detection. Each kernel type has a unique function, altering the image in specific ways. The article aims to provide a comprehensive overview of
8 min read
OpenCV Selective Search For Object Detection
OpenCV is a Python library that is used to study images and video streams. It basically extracts the pixels from the images and videos (stream of image) so as to study the objects and thus obtain what they contain. It contains low-level image processing and high-level algorithms for object detection
14 min read
NextJS Image Component
The image component in Next.js is powerful. It will assist you in optimizing and serving images efficiently. It has responsive loading and lazy loading built in, which can greatly boost the performance and user experience of your application by reducing the loading times of a page. This automaticall
8 min read
Alternative to scipy.misc.imresize() in Python
In this article, we will discuss the alternatives of scipy.misc.imresize() method in Python. But why do we need any alternative to that? The reason behind this is that in the new stable releases of the scipy this function has been deprecated and is no longer available. Let’s see these alternatives o
3 min read
imreadmulti() in Python Opencv
OpenCV (Open Source Computer Vision) library primarily focuses on image and video processing. To load a single image through OpenCV, imread() function is used. However, to load multiple images in a single object, imreadmulti() function is used. Images within a file are considered as a page. Although
4 min read
OpenCV - Invert Mask
In this article, we will learn how to invert a mask created on an image in OpenCV. Masking is a technique used to highlight a specific object from the image. It can be defined as setting certain pixels of an image to some null value such as 0 (black color) so only that portion of our image is highli
4 min read
Explain Image Plugins in WordPress
Images make the website more attractive and make the user engage with your content. But sometimes it becomes difficult to manage the images on your website and makes the website a little bit slow and unarranged. let's see some of the plugins which help in managing the images and make your WordPress
2 min read
How to Choose an Image Format for Screenshots?
Choosing the right image format for your screenshots is crucial for ensuring clarity and optimal file size. Different formats like PNG, JPEG, and others offer various benefits and drawbacks, depending on your needs. In this guide, we will explore the most common image formats for screenshots and pro
7 min read