How Insert Data into Table

aimtocode

SQL Database: Definition

The INSERT INTO statement is basically used to perform the task of inserting one or munltiple new records into the table of a database.

Syntax for Single record INSERT statement:

INSERT INTO table
(column1, column2, ... )
VALUES
(expression1, expression2, ... );

Syntax for Multiple record INSERT statement:

INSERT INTO table
(column1, column2, ... )
SELECT expression1, expression2, ...
FROM source_tables
[WHERE conditions];

Example:

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (1, 'Prayag', 21, 'Giridih', 2500.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (2, 'Rakesh', 23, 'Jamua', 1500.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (3, 'Pankaj', 24, 'Delhi', 2000.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (4, 'Satanand', 25, 'Mumbai', 6500.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (5, 'Mukesh', 21, 'Tamilnadu', 8500.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (6, 'Vikash', 22, 'Goa', 4500.00 );

Result:

+----+----------+-----+-----------+----------+
| ID | NAME     | AGE | ADDRESS   | SALARY   |
+----+----------+-----+-----------+----------+
|  1 | Prayag   |  21 | Giridih   |  2000.00 |
|  2 | Rakesh   |  23 | Jamua     |  1500.00 |
|  3 | Pankaj   |  24 | Delhi     |  2000.00 |
|  4 | Satanand |  25 | Mumbai    |  6500.00 |
|  5 | Mukesh   |  21 | TamilNadu |  8500.00 |
|  6 | Vikash   |  22 | Goa       |  4500.00 |
+----+----------+-----+-----------+----------+

Let's INSERT one more row in the same table.


INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (7, 'Rahul', 23, 'Punjab', 8500.00 );	

Result:

+----+----------+-----+-----------+----------+
| ID | NAME     | AGE | ADDRESS   | SALARY   |
+----+----------+-----+-----------+----------+
|  1 | Prayag   |  21 | Giridih   |  2000.00 |
|  2 | Rakesh   |  23 | Jamua     |  1500.00 |
|  3 | Pankaj   |  24 | Delhi     |  2000.00 |
|  4 | Satanand |  25 | Mumbai    |  6500.00 |
|  5 | Mukesh   |  21 | TamilNadu |  8500.00 |
|  6 | Vikash   |  22 | Goa       |  4500.00 |
|  6 | Rahul    |  23 | Punjab    |  8500.00 |
+----+----------+-----+-----------+----------+	
aimtocode