Inserting multiple rows in MySQL Table in Single Statement - MySQL Developer Tutorial

Inserting multiple rows in MySQL Table in Single Statement 

If you need to insert multiple rows of data into MySQL Table, you can use below syntax.

insert into TableName
(Column1,Column2,....)
Values (ValueForColumn1,ValueforColumn2,....),
(ValueForColumn1,ValueforColumn2,....),
(ValueForColumn1,ValueforColumn2,....);



Example : 

In below example, we are creating customer table and then insert multiple rows into customer table by using single insert statement.

create customer table syntax:


CREATE TABLE `customer` (
  `idcustomer` int(11) NOT NULL auto_increment,
  `firstname` varchar(50)  NULL,
  `lastname` varchar(30)  NULL,
  `age` int(11) DEFAULT NULL,
  `phonenumber` char(11) DEFAULT NULL,
  `dob` date DEFAULT NULL,
  `gender` char(1) NOT NULL,
  Constraint pk_idcustomer Primary key (idcustomer)

) ;


Insert multiple rows in MySQL Table.


insert into customer
(firstname,lastname,age,phonenumber,dob,gender)
values
('Aamir1','Shahzad1',39,'505-414000','1980-01-01','M'),
('Aamir2','Shahzad2',40,'505-4141000','1980-02-01','M');


Insert Multiple records in MySQL table in single Insert Statement - MySQL Tutorial

1 comment:

  1. Hi everyone. I've been using Whit-Label Card Issuing for several years now, and every time it pleasantly surprises me with its functionality and reliability. It is the perfect solution for those who want to keep their finances under control. The ability to synchronize with bank accounts and credit cards allows you to automatically track transactions, which saves a lot of time. And the budget planning and goal setting features help you keep your financial goals in sight and achieve them.

    ReplyDelete