473,700 Members | 2,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DROP TABLE, VIEW, ... only IF EXISTS

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
--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| Gregor Kovac | Gr**********@mi kropis.si |
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Jul 6 '06 #1
4 46033
"Gregor Kovac" <gr**********@m ikropis.siwrote : news:6y******** ************@ne ws.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.MYTABL E;
end if;
End

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

Cheers,
--
Konstantin Andreev.

Jul 6 '06 #2
"Gregor Kovac" <gr**********@m ikropis.siwrote in message
news:6y******** ************@ne ws.siol.net...
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
--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| Gregor Kovac | Gr**********@mi kropis.si |
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

Use the db2perf_quiet_d rop procedure. The source code is available on

ftp://ftp.software.ibm.com/ps/produc...perf-1.0.1.zip

In the file db2perf_utils.d b2 there is the procedure db2perf_quiet_d rop
which suppresses the 'not found' message.

The call :

CALL db2perf_quiet_d rop( 'procedure db2perf_crmsg' )@

drops the procedure db2perf_crmsg if this procedure exists.

Kind regards,
Paul
Jul 6 '06 #3
Konstantin Andreev wrote:
Begin atomic
if( exists(
select 1 from syscat.tables where tabschema = 'MYSCHEMA' and tabname =
'MYTABLE' )) then
drop table MYSCHEMA.MYTABL E;
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.MYTABL E;
* * 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
--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| Gregor Kovac | Gr**********@mi kropis.si |
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Jul 6 '06 #4
Paul Peters wrote:
>
Use the db2perf_quiet_d rop procedure. The source code is available on

ftp://ftp.software.ibm.com/ps/produc...perf-1.0.1.zip

In the file db2perf_utils.d b2 there is the procedure db2perf_quiet_d rop
which suppresses the 'not found' message.

The call :

CALL db2perf_quiet_d rop( 'procedure db2perf_crmsg' )@

drops the procedure db2perf_crmsg if this procedure exists.

Kind regards,
Paul
Cool, I like it :)) thanks.

Best regards,
Kovi
--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| Gregor Kovac | Gr**********@mi kropis.si |
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Jul 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
545
by: Snorkerz | last post by:
Can anyone help, I'm trying to change some code on an asp page, this line: mySQL="drop table snorkTable" does not seem to close the table. Net time the page is refreshed I'm told that Table 'snorkTable' already exists. I suspect my syntax is wrong - can anyone help?
2
6322
by: nigel | last post by:
Hello I am using a temp table called ##temp in an SProc but often get the message that the table already exists. Could this be because the SProc is being run by more than 2 webpages at the same time? Or is it because the sProc has an error and is not getting to the drop table line? I have tried adding a line to test if the object exists and to drop the table before I create it. If I drop it will it affect another instance
2
7060
by: Alanoly J. Andrews | last post by:
Hi, I have two tables (that I know of) in a database that seem to be corrupted. All SQL statements on the tables hang, "select * from..", "select count (*) from", "delete from..". I can't even drop the tables as the "drop table..." statement, too, hangs. But the tables do exist as they show up in "describe table <tabname> ". A "create table" statement fails saying that the table already exists.
8
8093
by: Yaro | last post by:
Hello Could anyone tell how can I drop table conditionally (UDB 8.2 Win) ? I have a script file create table_1@ create table_2@ etc.... I need add to this script statement like that
10
22758
by: Geoff Jones | last post by:
Hi I'm trying to drop a table by using: Dim cmd As New OleDbCommand("DROP TABLE IF EXISTS books", myconnection) cmd.ExecuteNonQuery() but I get a syntax error: "Syntax error in DROP TABLE or DROP INDEX"
3
2901
by: Irfan | last post by:
hi, All I have a table in Access and I am using a storedProcedure (Make-Table query) to overwrite this table. It gives an error that 'Table Already Exists', which is true. But i want it to continue overwriting the existing table and not stop and give me an error. In VB6 i would have used On error resume Next, but i havent got grips yet with VB.net exception handling.
4
2001
by: The VanDerbeck Group | last post by:
The code below generates the indicated error. As a newbie to vb and SQL I have no idea how to track this down. I did verify that the connection state is open. My suspicion is that I have to connect to a seperate "sysobjects" database??? THE CODE: Dim oSQLConnection As New SqlConnection("data source =" _ & "psi-sbs2k3 ;" _ & "initial catalog = 'JHH PRODUCT DATA' ;" _
1
3576
by: Dragan Matic | last post by:
if exists (select * from sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table . GO For instance, this is a valid script in Ms SQL, it will drop table pp_fisk only if it exists, is there a way to do something similar in Postgres? Tnx in advance. Dragan
5
13785
by: Romulo NF | last post by:
Greetings, Im back here to show the new version of the drag & drop table columns (original script ). Ive found some issues with the old script, specially when trying to use 2 tables with drag&drop on the same page (which was not possible). Now ive a new concept of the script, more object oriented. Ive also commented the whole code so you guys can easier understand it engine. What exactly we need when trying to make a column drag &...
0
8649
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7819
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5904
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4408
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4660
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.