Quote:
Originally posted by alwick
I would like to verify that a table or view exists before executing a Drop on the view or table.
Is there a way to do this without creating a stored procedure?
the "if" keyword is not available in an sql statement outside of a stored prodedure.
I am using UDB PE 8.1 on Windows XP using JDBC with the IBM 1.3.1 JDK.
|
Depending on what you REALLY need, there are two ways to do it:
1) You don't care if the table exists -- you just need to ensure that your SQL script does not terminate when you try to drop a non-existent table. In that case put this in your sql script:
update command options using s off;
drop table schemaname.tablename;
update command options using s on;
The above will tell CLP not to terminate in case of a SQL error. Regardless of the result of the DROP command execution of the script will continue.
2) You actually need to know if the table exist. In that case you'll have to use a batch file, like this:
db2 drop table schema.tabname
if errorlevel 0 goto label1
goto label2
:label1
echo table exists
rem do stuff
goto endoffile
:label2
echo table missing
rem do other stuff
:endoffile
Hope this helps.
Nick