All for Joomla All for Webmasters

SQL INSERT INTO VALUE

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);

It will show the following table as the final result.

ROLL_NO NAME AGE CITY
1 ABHIRAM 22 ALLAHABAD
2 ALKA 20 GHAZIABAD
3 DISHA 21 VARANASI
4 ESHA 21 DELHI
5 MANMEET 23 JALANDHAR

You can create a record in CUSTOMERS table by using this syntax also.

  1. INSERT INTO CUSTOMERS
  2. VALUES (6, PRATIK, 24, KANPUR);

The following table will be as follow:

ROLL_NO NAME AGE CITY
1 ABHIRAM 22 ALLAHABAD
2 ALKA 20 GHAZIABAD
3 DISHA 21 VARANASI
4 ESHA 21 DELHI
5 MANMEET 23 JALANDHAR
6 PRATIK 24 KANPUR
PinIt
submit to reddit

Leave a Reply

Top