Inserting a list of names in a table using stored procedure

Inserting a list of names in a table using stored procedure

am 20.02.2006 16:02:13 von markbartolo

Hi,
I have the following:

INSERT IGNORE INTO names (name) VALUES ('John'),('Peter');

In the above query, I want to pass an unknown amount of names to the
insert query.

I tried a stored procedure with the following:

INSERT IGNORE INTO names (name) VALUES (paramList);

where paramList I set it as LongText, and passed paramList =
('John'),('Peter'); but it didn't work.

Is there a solution to insert a number of names for example by using a
stored procedure in MySql 5.0.

Re: Inserting a list of names in a table using stored procedure

am 21.02.2006 03:31:25 von Bill Karwin

wrote in message
news:1140447733.666794.103890@g44g2000cwa.googlegroups.com.. .
> Hi,
> I have the following:
>
> INSERT IGNORE INTO names (name) VALUES ('John'),('Peter');
>
> In the above query, I want to pass an unknown amount of names to the
> insert query.

Insert one record at a time, using a loop. You can do this either in a
stored procedure, or in your application code.

Regards,
Bill K.

Re: Inserting a list of names in a table using stored procedure

am 21.02.2006 10:01:54 von markbartolo

Thanks Bill.....

Do you think using a stored procedure, and therefore looping through
say, 30 names to insert them one by one , improves the efficiency of
the system, rather then just doing an INSERT INTO statement in the
application code?

Thanks.

Re: Inserting a list of names in a table using stored procedure

am 21.02.2006 16:50:25 von Michael Austin

markbartolo@gmail.com wrote:

> Thanks Bill.....
>
> Do you think using a stored procedure, and therefore looping through
> say, 30 names to insert them one by one , improves the efficiency of
> the system, rather then just doing an INSERT INTO statement in the
> application code?
>
> Thanks.
>

either way it does exactly the same thing... something still has to loop through
all of the values and write them into the table.

--
Michael Austin.
DBA Consultant
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)

Re: Inserting a list of names in a table using stored procedure

am 21.02.2006 19:04:37 von markbartolo

OK...Thanks