Multiple data input at the same time in MySQL?

MySQLMySQLi Database

Following is the syntax −

insert into yourTableName values(yourValue1,yourValue2,.....N),
(yourValue1,yourValue2,.....N),
(yourValue1,yourValue2,.....N),
(yourValue1,yourValue2,.....N),
.
.
.
N

Let us create a table −

mysql> create table demo56
−> (
−> id int,
−> first_name varchar(20),
−> last_name varchar(20),
−> age int
−> );
Query OK, 0 rows affected (1.91 sec)

Insert some records into the table with the help of insert command −

mysql> insert into demo56 values(1,'John','Smith',23),
−> (2,'David','Miller',21),
−> (3,'Chris','Brown',22),
−> (4,'Carol','Taylor',20);
Query OK, 4 rows affected (0.10 sec)
Records: 4 Duplicates: 0 Warnings: 0

Display records from the table using select statement −

mysql> select *from demo56;

This will produce the following output −

+------+------------+-----------+------+
| id   | first_name | last_name | age  |
+------+------------+-----------+------+
|    1 | John       | Smith     |   23 |
|    2 | David      | Miller    |   21 |
|    3 | Chris      | Brown     |   22 |
|    4 | Carol      | Taylor    |   20 |
+------+------------+-----------+------+
4 rows in set (0.00 sec)
raja
Published on 20-Nov-2020 07:04:22
Advertisements