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 > Command Line SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-20-04, 11:25
atmosphere atmosphere is offline
Registered User
 
Join Date: Aug 2004
Posts: 19
Command Line SQL

Hey

I have a few queries, creates, and drops I want to put in a single sql file. I will then execute this sql file from the db2 command line environment.

The sql will basically be like the following

-------------------------
drop table
create table
drop table
-------------------------

Also, if possible i would like to make the first drop table into 'drop table if exists'. Is this possible? How Could i do this?
Reply With Quote
  #2 (permalink)  
Old 09-20-04, 13:03
rubystep rubystep is offline
Registered User
 
Join Date: Sep 2003
Posts: 85
How about writing a shell script which would connect to the database, test for existence of the table and if so, drop the table?
Or, do you care if one issues a DROP TABLE and the table doesn't exist?
Ruby
Reply With Quote
  #3 (permalink)  
Old 09-20-04, 13:09
atmosphere atmosphere is offline
Registered User
 
Join Date: Aug 2004
Posts: 19
Im not sure if I care if i drop a table which doesnt exist.. what happens? If an error message is simply generated tehn thats fine.


The main point of the question was if i can have multiple sql statements inside a single text file. I just want my batch file to run the sql file. Im working in a restricted environment so that has to be the format. One batch file which just runs the one sql file
Reply With Quote
  #4 (permalink)  
Old 09-20-04, 14:42
rubystep rubystep is offline
Registered User
 
Join Date: Sep 2003
Posts: 85
Sure thing. You can have multiple SQL statements in a "batch" file.
And if there's a DROP TABLE tablename and the table doesn't exist, so the output would be something like:
db2 drop table x
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0204N "schemaname.X" is an undefined name. SQLSTATE=42704
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