If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Help with inserting SQL statements into DB2 database from file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-12-09, 20:06
italia1980 italia1980 is offline
Registered User
 
Join Date: Mar 2009
Posts: 2
Help with inserting SQL statements into DB2 database from file

I have a text file containing SQL statements. I wish to run this file in DB2 database to execute the statements. The file contains a series of simple row inserts.

eg.
INSERT INTO x (a, b, c, d, e) VALUES ('f', 'g', 'h', 'i', 'j')
INSERT INTO ....
etc.

Can anyone please assist? I aware that there is an 'insert into x from file y' command somewhere.

Thanks.
Reply With Quote
  #2 (permalink)  
Old 03-12-09, 21:35
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Put this in a file:
connect to sample;

INSERT INTO x (a, b, c, d, e) VALUES ('f', 'g', 'h', 'i', 'j');
INSERT INTO x (a, b, c, d, e) VALUES ('f', 'g', 'h', 'i', 'j');

connect reset;
The from command window:

db2 -tvf <file-name>
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 03-13-09, 03:46
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Alternatively, have a look at the "import" command.
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #4 (permalink)  
Old 03-13-09, 05:31
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
italia1980,
if you don't have ";" at the end of each command, you must have each command in its separate row. If so, you can use command:
db2 -f <file-name>
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On