SQLite INSERT INTO Statement is utilized to add new columns of information into a table in the data set.
Syntax
Following are the two fundamental sentence structures of INSERT INTO explanation.
INSERT INTO TABLE_NAME [(column1, column2, column3,...columnN)]
VALUES (value1, value2, value3,...valueN);
Here, column1, column2,...columnN are the names of the segments in the table into which you need to embed information.
You should not indicate the column(s) name in the SQLite inquiry on the off chance that you are adding values for all the segments of the table. Be that as it may, ensure the request for the qualities is in similar request as the sections in the table. The SQLite INSERT INTO language structure would be as per the following −
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);
Example
Think of you as of now have made COMPANY table in your testDB.db 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
);
Presently, the accompanying assertions would make six records in COMPANY 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 );
You can make a record in COMPANY table utilizing the subsequent punctuation as follows −
INSERT INTO COMPANY VALUES (7, 'James', 24, 'Houston', 10000.00 );
All the above assertions would make the accompanying records in COMPANY table. In the following part, you will figure out how to show every one of these records from a 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
Populate One Table Using Another Table
You can populate information into a table through select assertion over another table gave another table has a bunch of fields, which are needed to populate the principal table. Here is the linguistic structure −
INSERT INTO first_table_name [(column1, column2, ... columnN)]
SELECT column1, column2, ...columnN
FROM second_table_name
[WHERE condition];
Until further notice, you can skirt the above assertion. To start with, how about we learn SELECT and WHERE conditions which will be shrouded in resulting sections.