Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / July 2006

Tip: Looking for answers? Try searching our database.

DROP TABLE, VIEW, ... only IF EXISTS

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gregor Kovač - 06 Jul 2006 14:49 GMT
Hi!

Is it possible do to something like this:
DROP TABLE MY_TABLE ONLY IF EXISTS
and the same for views, indexes, procedures, .... ?

Best regards,
       Kovi
Signature

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

| Gregor Kovac |    Gregor.Kovac@mikropis.si    |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|  In A World Without Fences Who Needs Gates?   |
|              Experience Linux.                |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Konstantin Andreev - 06 Jul 2006 15:13 GMT
"Gregor Kovac" <gregor.kovac@mikropis.si> wrote: news:6y8rg.4173$oj5.1414452@news.siol.net...

> Is it possible do to something like this: DROP TABLE MY_TABLE ONLY IF EXISTS
> and the same for views, indexes, procedures, .... ?

Long and cumbersome way. Just drop and ignore errors. But, if you insist...
For table:
--------------
Begin atomic
   if( exists(
       select 1 from syscat.tables where tabschema = 'MYSCHEMA' and tabname = 'MYTABLE'
   )) then
       drop table MYSCHEMA.MYTABLE;
   end if;
End

--------------
For index: syscat.table -> syscat.indexes + 2 extra conditions: indschema & indname.
... and so on...

Cheers,
--
Konstantin Andreev.
Gregor Kovač - 06 Jul 2006 15:19 GMT
> Begin atomic
> if( exists(
[quoted text clipped - 3 lines]
> end if;
> End

Hmm.. but it does not work for me.
I've saved this into a file TEST.SQL:
Begin atomic
    if (exists(select 1 from syscat.tables where tabschema = 'MYSCHEMA' and
tabname = 'MYTABLE')) then
        drop table MYSCHEMA.MYTABLE;
    end if;
End
#

ran it like:
db2 -td# -f TEST.SQL

and got:
B21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL0104N  An unexpected token "   " was found following "Begin atomic ".
Expected tokens may include:  "<space>".  LINE NUMBER=2.  SQLSTATE=42601

I've tried this approach, but to no avail.

Best regards,
       Kovi
Signature

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

| Gregor Kovac |    Gregor.Kovac@mikropis.si    |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|  In A World Without Fences Who Needs Gates?   |
|              Experience Linux.                |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Paul Peters - 06 Jul 2006 15:18 GMT
> Hi!
>
[quoted text clipped - 9 lines]
> |              Experience Linux.                |
> -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

Use the db2perf_quiet_drop procedure. The source code is available on

ftp://ftp.software.ibm.com/ps/products/db2/tools/db2perf-1.0.1.zip

In the file db2perf_utils.db2 there is the procedure db2perf_quiet_drop
which suppresses the 'not found' message.

The call :

CALL db2perf_quiet_drop( 'procedure db2perf_crmsg' )@

drops the procedure db2perf_crmsg if this procedure exists.

Kind regards,
Paul
Gregor Kovač - 06 Jul 2006 15:24 GMT
> Use the db2perf_quiet_drop procedure. The source code is available on
>
[quoted text clipped - 11 lines]
> Kind regards,
> Paul

Cool, I like it :)) thanks.

Best regards,
       Kovi
Signature

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

| Gregor Kovac |    Gregor.Kovac@mikropis.si    |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|  In A World Without Fences Who Needs Gates?   |
|              Experience Linux.                |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.