SQLite’s INSERT INTO Statement is used to add a new data row to a table in the database. There are two basic syntaxes for INSERT INTO statements, as follows: Here, column1, column2,…columnN is the name of the column in the table where the data is to be inserted. If you want to add values to all columns in the table, you may not need to specify column names in the SQLite query. However, make sure that the order of the values is the same as the order of the columns in the table. The INSERT INTO syntax for SQLite is as follows: Suppose you are already in the Now, the following statement will be used in the You can also use the second syntax in the All of the above statements will be in the You can use the For the time being, you can skip the above statement and learn what is described in later chapters. 1.12.1. Grammar ¶
INSERT INTO TABLE_NAME [(column1, column2, column3,...columnN)]
VALUES (value1, value2, value3,...valueN);
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);
1.12.2. Example ¶
testDB.db
The COMPANY table is created in, as follows:sqlite> CREATE TABLE COMPANY(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);
COMPANY
Create six records in the table:INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (1, 'Paul', 32, 'California', 20000.00 );
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (2, 'Allen', 25, 'Texas', 15000.00 );
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (3, 'Teddy', 23, 'Norway', 20000.00 );
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (5, 'David', 27, 'Texas', 85000.00 );
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (6, 'Kim', 22, 'South-Hall', 45000.00 );
COMPANY
Create a record in the table as follows:INSERT INTO COMPANY VALUES (7, 'James', 24, 'Houston', 10000.00 );
COMPANY
Create the following records in the table. The next chapter will teach you how to display all of these records from one table.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
1.12.3. Use one table to populate another table ¶
select
Statement to populate the data into another table. Here is the syntax:INSERT INTO first_table_name [(column1, column2, ... columnN)]
SELECT column1, column2, ...columnN
FROM second_table_name
[WHERE condition];
SELECT
And
WHERE
Clause.