1. Make a TXT file and name it like file_name.sql with SQL statements seperated with ; character.
Insert into tab1 values (1,2,3);
Insert into tab2 values (1,2,3);
2. In DB2 Command Windows execute script by typing:
db2 -tf path_and_file_name.sql
db2 -tf c:\temp\file_name.sql -> On Windows
db2 -tf /home/db2user/file_name.sql -> On Unix/Linux
Hope this helps,
Thanks for replying. What I actually need is how to generate the insert statements in the first place. I know I can do it manually like, select 'insert into table_1 (col_1, col_2 ...) values (value_1, value_2, ...)' from table_1. But I have a lot of tables, I can't possibly manually write the insert script for all of them one by one. Hence, I want to do it using some utility or tool or command easily.
I know DB2 Commander 2000 Pro can generate insert scripts easily but there is problem with datetime field, because datetime field in DB2 has format of "2003-07-02-20.06.35.000000" but in DB Commander 2000 Pro is shown as "07/02/2003 8:06:35 PM". After generating the insert scripts from DB Commander 2000 Pro, the timestamp field will cause error when running the insert scripts.
Pardon my ignorance but I don't understand the question clearly. Insert statements contain user provided value unless all the values are same then you can use java or c++ or even some scripting language to create inserts. Otherwise I don't see there is any tool which will do that for you. Other thing is that all the table might have different structure so it's hard to create something generic unless used through some programming language.
Originally posted by ncs_vrl
Is there anyone who can tell me how to generate insert scripts in DB2 for all my tables?
One way to accomplish this would be to create a text file with comma-delimited values (eg. using MS Excel or any text editor). You can also write a small application using whatever language you're comfortable with. Contents of that file can then be IMPORTed or LOADed into your table.