SQLite Insert Query
To add data into a table, the INSERT INTO statement is used in SQLite.
Syntax 1: If adding values to only some of the columns in a table or if adding values in random order.
INSERT INTO TABLE_NAME [(column_1, column_2, column_3,...column_N)] VALUES (value_1, value_2, value_3,...value_N);
Syntax 2: If adding values to all the columns in a table and in the same order as that of the columns in the table.
INSERT INTO TABLE_NAME VALUES (value_1, value_2, value_3,...value_N);
Example:
INSERT INTO TEACHERS (ID, NAME, SUBJECT) VALUES (1, 'Jim', 'English'); INSERT INTO TEACHERS VALUES (2, 'John', 'Geology'); INSERT INTO TEACHERS VALUES (3, 'Watson', 'French'); INSERT INTO TEACHERS VALUES (4, 'Holmes', 'Chemistry'); INSERT INTO TEACHERS VALUES (5, 'Tony', 'Physics'); |
Explanation:
Here we have uses both the syntaxes to insert values in an already created table “TEACHERS”. To check the table data execute the below query.
SELECT * FROM TEACHERS;
Output:
ID | NAME | SUBJECT |
1 | Jim | English |
2 | John | Geology |
3 | Watson | French |
4 | Holmes | Chemistry |
5 | Tony | Physics |