MySQL INSERT Statement

Insert is used to to insert data into the table. We have two methods to insert data in the table:

Method 1 Syntax:

insert into table_name values(value1,value2,value3,…..)

mysql> create table emp1(empno decimal(4,0),empname varchar(20)); #Create table Query OK, 0 rows affected (0.46 sec) mysql> select * from emp1; #Now table is empty Empty set (0.00 sec) mysql> insert into emp1 values(1000,'Karunakar'); Query OK, 1 row affected (0.12 sec) mysql> insert into emp1 values(1001,'Kalpesh'); Query OK, 1 row affected (0.02 sec) mysql> select * from emp1; #Table has 2 rows +-------+-----------+ | empno | empname | +-------+-----------+ | 1000 | Karunakar | | 1001 | Kalpesh | +-------+-----------+ 2 rows in set (0.00 sec)

Method2 Syntax:Skipping columns.

mysql> insert into emp1(empno) values(1002); Query OK, 1 row affected (0.13 sec) mysql> select * from emp1; +-------+-----------+ | empno | empname | +-------+-----------+ | 1000 | Karunakar | | 1001 | Kalpesh | | 1002 | NULL | +-------+-----------+ 3 rows in set (0.09 sec)