SQL INSERT STATEMENT

SQL INSERT statement is a SQL query. It is used to insert a single or a multiple records in a table.

There are two ways to insert data in a table:

  1. By SQL insert into statement
    1. By specifying column names
    2. Without specifying column names
  2. By SQL insert into select statement

1) Inserting data directly into a table

You can insert a row in the table by using SQL INSERT INTO command.

There are two ways to insert values in a table.

In the first method there is no need to specify the column name where the data will be inserted, you need only their values.


  1. INSERT INTO table_name  
  2. VALUES (value1, value2, value3....); 

The second method specifies both the column name and values which you want to insert.

  1. INSERT INTO table_name (column1, column2, column3....)  
  2. VALUES (value1, value2, value3.....);  




Let's take an example of table which has five records within it.

  1. INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)  
  2. VALUES (1, ABHIRAM, 22, ALLAHABAD);  
  3. INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)  
  4. VALUES (2, ALKA, 20, GHAZIABAD);  
  5. INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)  
  6. VALUES (3, DISHA, 21, VARANASI);  
  7. INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)  
  8. VALUES (4, ESHA, 21, DELHI);  
  9. INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)  
  10. VALUES (5, MANMEET, 23, JALANDHAR);  

No comments:

Post a Comment