You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by tbrazao <ti...@emation.pt> on 2007/04/17 20:07:54 UTC

Drop Table

Hi,

i'm a new user of derby.

My question is about the ideia of sql : "drop table if exists ...".

I read some explanations in this forum, but i didn´t find answers to work in
sql line commander.

I know that derby doens't support this job, but i want to ensure that if an
table exists it is dropped. So i think we can use something like...

select count(*) from SYS.SYSTABLES where TABLENAME = tableName,

where tableName  could be an arg for an procedure,
but i don´t know how to relate this with an drop call. It was simple if we
have one "if" clause. 

The problem is that i need to do this without java sintax, i know that seems
strange, but life it's strange and nobody cares about it...

If anyone could help, Thanks!

And sorry my English!
-- 
View this message in context: http://www.nabble.com/Drop-Table-tf3595128.html#a10042954
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Re: Drop Table

Posted by Stanley Bradbury <St...@gmail.com>.
Mike Matrigali wrote:
>
>
> tbrazao wrote:
>> Hi,
>>
>> i'm a new user of derby.
>>
>> My question is about the ideia of sql : "drop table if exists ...".
>>
>> I read some explanations in this forum, but i didn´t find answers to 
>> work in
>> sql line commander.
>>
>> I know that derby doens't support this job, but i want to ensure that 
>> if an
>> table exists it is dropped. So i think we can use something like...
>>
>> select count(*) from SYS.SYSTABLES where TABLENAME = tableName,
>>
>> where tableName  could be an arg for an procedure,
>> but i don´t know how to relate this with an drop call. It was simple 
>> if we
>> have one "if" clause.
>> The problem is that i need to do this without java sintax, i know 
>> that seems
>> strange, but life it's strange and nobody cares about it...
>>
>> If anyone could help, Thanks!
>
> Why not just drop the table and let derby return an error if it did 
> not exist?
>
>>
>> And sorry my English!
>
>
You will need to use the Derby API (Java) to perform conditional 
processing like you describe.  The java code can be hidden from the 
end-users and invoked using IJ by storing it in the database and 
defining it as a procedure.  The procedure would take the table name, 
drop the table - it would catch and discard the exception thrown if the 
table does not exist. 

Example Java code that does something similar to this (checks for 
existance based on a select statement) can be found in the 10.2 Derby 
distribution in the method 'wwdChk4Table' defined in 'WwdUtils.java' in 
the folder: <DERBY_INSTALL>\demo\programs\workingwithderby.

HTH




Re: Drop Table

Posted by Mike Matrigali <mi...@sbcglobal.net>.

tbrazao wrote:
> Hi,
> 
> i'm a new user of derby.
> 
> My question is about the ideia of sql : "drop table if exists ...".
> 
> I read some explanations in this forum, but i didn´t find answers to work in
> sql line commander.
> 
> I know that derby doens't support this job, but i want to ensure that if an
> table exists it is dropped. So i think we can use something like...
> 
> select count(*) from SYS.SYSTABLES where TABLENAME = tableName,
> 
> where tableName  could be an arg for an procedure,
> but i don´t know how to relate this with an drop call. It was simple if we
> have one "if" clause. 
> 
> The problem is that i need to do this without java sintax, i know that seems
> strange, but life it's strange and nobody cares about it...
> 
> If anyone could help, Thanks!

Why not just drop the table and let derby return an error if it did not 
exist?

> 
> And sorry my English!