Saturday, October 19, 2019

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:

  1. INSERT INTO TABLE_NAME [(column1, column2, column3,...columnN)]    
  2. 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:
  1. 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:
  1. INSERT INTO STUDENT (ID,NAME,AGE,ADDRESS,FEES)  
  2. VALUES (1, 'Ajeet', 27, 'Delhi', 20000.00);  
  3. INSERT INTO STUDENT (ID,NAME,AGE,ADDRESS,FEES)  
  4. VALUES (2, 'Akash', 25, 'Patna', 15000.00 );  
  5. INSERT INTO STUDENT (ID,NAME,AGE,ADDRESS,FEES)  
  6. VALUES (3, 'Mark', 23, 'USA', 2000.00 );  
  7. INSERT INTO STUDENT (ID,NAME,AGE,ADDRESS,FEES)  
  8. VALUES (4, 'Chandan', 25, 'Banglore', 65000.00 );  
  9. INSERT INTO STUDENT (ID,NAME,AGE,ADDRESS,FEES)  
  10. 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.
  1. 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:
  1. SELECT * FROM STUDENT;  
SQLite Insert query 3

No comments:

Post a Comment

How to DROP SEQUENCE in Oracle?

  Oracle  DROP SEQUENCE   overview The  DROP SEQUENCE  the statement allows you to remove a sequence from the database. Here is the basic sy...