![]() |
VOOZH | about |
This article explains how to insert data into an SQLite table from Python using the sqlite3 module. The INSERT INTO statement is used to insert new rows into a table. There are two main methods for inserting data:
Let's discuss both these methods in detail with example:
In this approach, we insert data by specifying the values for all columns without mentioning column names.
INSERT INTO table_name VALUES (value1, value2, value3,...);
Below is a program that depicts how to insert data in an SQLite table using only values. Then display the content of the table and commit it to the database.
Output:
👁 ImageSQLite3:
👁 ImageIn the second method we will specify both the columns which we want to fill and their corresponding values.
Syntax:
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
The below program is similar to that of the 1st program, but we insert values into the table by reordering the names of the columns with values as in the 2nd syntax.