Q

How can I insert multiple rows in a DB2 table?

Learn how to insert multiple rows into a DB2 table using one INSERT statement in this tip from Craig Mullins.

How can I insert multiple rows in a DB2 table? Our system is currently on the sixth version. Please advise.

Well, one way is to issue multiple INSERT statements, one for each row. But I don't think that is what you are asking. If you are looking for a way to insert multiple rows into a DB2 table using one INSERT statement, that is possible using a SELECT within the insert. For example:

 INSERT INTO TABLE1 SELECT C1, C2, C3 FROM TABLE2;

Of course, you better make sure that the columns being selected from TABLE2 "match up" with the columns of the TABLE1. But what if you wish to insert multiple rows into a table and that data is not already in another DB2 table. In that case, you should use the LOAD utility. DB2 uses the LOAD utility to bulk load multiple rows into a table and it will be more efficient than a series of INSERT statements. Information on how to use the LOAD utility can be found in the IBM DB2 V7 manual named "Utility Guide and Reference" (SC26-9945) which can be downloaded from the IBM web site for free. http://www-3.ibm.com/software/data/db2/library/

This was first published in December 2002

Dig deeper on IBM DB2 management

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchBusinessAnalytics

SearchAWS

SearchContentManagement

SearchOracle

SearchSAP

SearchSOA

SearchSQLServer

Close