SQL Insert Statement

INSERT INTO command is used to add new record into the table.

there is two way to insert a record into the table.

1) If you want to insert records in all fields(columns) then do not need defines the columns.

Syntax:-


INSERT INTO table_name 
values(value_1,value_2,value_3,value_4....value_n) 

Example:-


INSERT INTO employees 
values(1,"Virat","Kohli","virat@abc.com","delhi") 

Now check the new record is saved into employees table


 SELECT * FROM employees

Output:-


+----+------------+-----------+----------------+------------+
| id | first_name | last_name | email          | address    |
+----+------------+-----------+----------------+------------+
|  1 | Virat      | Kohli     | virat@abc.com  | delhi      |
+----+------------+-----------+----------------+------------+

2) If you want to insert records in some fields (columns) then it should be defined.

Syntax:-


INSERT INTO table_name(column_1,column_2,column_3)
values(value_1,value_2,value_3) 

Example:-


INSERT INTO employees("id","first_name","email") 
values(2,"Rohit","rohit@abc.com")

Now check the new record is saved into employees table


 SELECT * FROM employees

Output:-


+----+------------+-----------+----------------+------------+
| id | first_name | last_name | email          | address    |
+----+------------+-----------+----------------+------------+
|  1 | Virat      | Kohli     | virat@abc.com  | delhi      |
|  2 | rohit      | NULL      | rohit@abc.com  | NULL       |
+----+------------+-----------+----------------+------------+