SQLite Insert Query

In SQLite, INSERT INTO statement is used to add new rows of data into a table. After creating the table, this command is used to insert data into the table.

There are two types of basic syntaxes for INSERT INTO statement:

Syntax1:

snippet
INSERT INTO TABLE_NAME [(column1, column2, column3,...columnN)]  
VALUES (value1, value2, value3,...valueN);

Here, column1, column2, column3,...columnN specifies the name of the columns in the table into which you have to insert data.

You don't need to specify the columns name in the SQlite query if you are adding values to all the columns in the table. But you should make sure that the order of the values is in the same order of the columns in the table.

Then the syntax will be like this:

Syntax2:

snippet
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);

Let's take an example to demonstrate the INSERT query in SQLite database.

We have already created a table named "STUDENT". Now enter some records in that table.

Inserting values by first method:

snippet
INSERT INTO STUDENT (ID,NAME,AGE,ADDRESS,FEES)
VALUES (1, 'Ajeet', 27, 'Delhi', 20000.00);
INSERT INTO STUDENT (ID,NAME,AGE,ADDRESS,FEES)
VALUES (2, 'Akash', 25, 'Patna', 15000.00 );
INSERT INTO STUDENT (ID,NAME,AGE,ADDRESS,FEES)
VALUES (3, 'Mark', 23, 'USA', 2000.00 );
INSERT INTO STUDENT (ID,NAME,AGE,ADDRESS,FEES)
VALUES (4, 'Chandan', 25, 'Banglore', 65000.00 );
INSERT INTO STUDENT (ID,NAME,AGE,ADDRESS,FEES)
VALUES (5, 'Kunwar', 26, 'Agra', 25000.00 );
SQLite Insert query 1

Second Method:

You can also insert the data into the table by second method.

snippet
INSERT INTO STUDENT VALUES (6, 'Kanchan', 21, 'Meerut', 10000.00 );
SQLite Insert query 2

Output:

You can see the output by using the SELECT statement:

snippet
SELECT * FROM STUDENT;
SQLite Insert query 3
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents