Insert multiple rows into a table in MariaDB/MySQL

For testing insert multiple rows into table in MySQL or MariaDB

Following are the commands to create a table and insert multiple data through a procedure in MySQL or MariaDB for testing:

  1. Create a table with name TEST.

create table test (
id int not null auto_increment primary key,
name1 varchar(10)

)

2. Create a procedure with Procedure Name PN

delimiter $$
create or replace procedure proc_insert (in p_range int)
begin
declare i int default 0;
while i < p_range do
insert into test (name1) values (concat('1d',i));
set i = i + 1;
end while;
end $$
delimiter ;

3. Insert the rows by calling the procedure if you want to enter 10000 rows then pass 10000 as parameter value.

call proc_insert(10000);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.