when fails, I always get a warning message, it is a little annoyed.
--CELKO-- wrote:[color=blue]
> Why just drop the table? If the drop works, then you have what you
> wanted. If the drop fails, then you have what you wanted anyway.[/color]
Ken wrote:[color=blue]
> when fails, I always get a warning message, it is a little annoyed.[/color]
Actually that would we an error. In the CLP you can easily suppress the
error by calling
UPDATE COMMAND OPTIONS USING <magicyouneedto lookupininforma tioncenter> OFF
DROP TABLE ..
UPDATE COMMAND OPTIONS USING ... ON
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
UPDATE COMMAND OPTIONS USING o OFF;
DROP whatever you like;
UPDATE COMMAND OPTIONS USING o ON;
Bernd
--
"Ja, alles meine Herren" sprach Fürst Lichnowsky. "Ooch det roochen?"
"Ja, auch das Rauchen." "Ooch im Tiergarten?" "Ja, auch im Tiergarten
darf geraucht werden, meine Herren." Und so endeten die Barrikadenkämpf e
des 18. März in Berlin
There is no way to do that directly, but a lot of things can be done to
do the same, depending on your needs.
If you are executing statements:
SELECT COUNT(*) FROM SysCat.Tables WHERE TabName = <Name>
And if the result is not 0, DROP TABLE ....
This can be a PROCEDURE as well:
CREATE PROCEDURE Drop_Table (Name VARCHAR(0128))
BEGIN
DECLARE A INTEGER;
SELECT COUNT(*) INTO A FROM SysCat.Tables WHERE TabName = Name;
IF A = 1 THEN EXECUTE IMMEDIATE "DROP TABLE " || <tabname>; END IF;
END
The only issue with the above, is that if someone else DROPs the TABLE
in between the two statements, such as in a concurrent process, this
will still produce the error. If you were DELETEing a row from a TABLE,
you could LOCK the TABLE to guarantee a static state, but there is no
equivalent LOCK SCHEMA that i know of.
Instead, the more "apropriate " way to do the above would be to DROP it
and simple catch the error with a DECLARE CONTINUE HANDLER FOR
SQLEXCEPTION, or more specifically, SQL0204N, and just ignore the
error.
Brian Tkatch wrote:
[color=blue]
> There is no way to do that directly, but a lot of things can be done to
> do the same, depending on your needs.
>
> If you are executing statements:
>
> SELECT COUNT(*) FROM SysCat.Tables WHERE TabName = <Name>
>
> And if the result is not 0, DROP TABLE ....
>
> This can be a PROCEDURE as well:
>
> CREATE PROCEDURE Drop_Table (Name VARCHAR(0128))
> BEGIN
> DECLARE A INTEGER;
> SELECT COUNT(*) INTO A FROM SysCat.Tables WHERE TabName = Name;
> IF A = 1 THEN EXECUTE IMMEDIATE "DROP TABLE " || <tabname>; END IF;
> END
>
> The only issue with the above, is that if someone else DROPs the TABLE
> in between the two statements, such as in a concurrent process, this
> will still produce the error. If you were DELETEing a row from a TABLE,
> you could LOCK the TABLE to guarantee a static state, but there is no
> equivalent LOCK SCHEMA that i know of.[/color]
Well, that's what isolation levels are for to prevent. Given that a DROP
TABLE actually amounts to a DELETE on the catalog (aside from the physical
changes), you won't run into any problem with isolation RR.
--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Brian Tkatch wrote:
[color=blue]
> Please explain further, i do not understand.
>
> Can you give me an example of setting the isolation level to allow the
> DROP of a TABLE when a concurrent process DROPs it first?[/color]
Just do this:
SET ISOLATION LEVEL TO RR
Then all operations are done in what the SQL standard calls "serializab le",
i.e. no concurrency issues. So the transaction that checks for the
existence of the table via the SELECT COUNT(*) FROM syscat.tables acquires
read locks on the catalog, and another transaction cannot simply drop the
table, disregarding those read locks. That's just the usual locking stuff.
--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Comment