Discussions
Categories
- 17.9K All Categories
- 3.4K Industry Applications
- 3.3K Intelligent Advisor
- 62 Insurance
- 536.1K On-Premises Infrastructure
- 138.2K Analytics Software
- 38.6K Application Development Software
- 5.7K Cloud Platform
- 109.4K Database Software
- 17.5K Enterprise Manager
- 8.8K Hardware
- 71.1K Infrastructure Software
- 105.2K Integration
- 41.6K Security Software
drop table if exists

Some other RDBMS - for example MySQL and postgreSQL: PostgreSQL: Documentation: 9.4: DROP TABLE - support a "drop table if exists" command that avoids an error if you try to drop a table that does actually not exists. I think that's sometimes useful.
Comments
-
A nice idea, but not really necessary. You can write a simple error routine to solve this problem in actual ORACLE DB Version.
-
A nice idea, but not really necessary. You can write a simple error routine to solve this problem in actual ORACLE DB Version.
yes, "not really necessary" is the fitting category - but on the other hand it should be quite cheap to implement.
-
not required as it errors out
-
Getting error is more logical. Table or view doesn't exist error comes even when someone tries to select from non-existent table so it absolutely makes sense to get the same error when someone tries to drop it.
Thanks,
Abhi
-
Isn't this what BEGIN/EXCEPTION is for?
Rather than get an error, you just go to the exception, and handle the missing object there.
-
Isn't this what BEGIN/EXCEPTION is for?
Rather than get an error, you just go to the exception, and handle the missing object there.
Not really. BEGIN / EXCEPTION is plsql or at least an anonymous block in SQL.
DROP TABLE is sql. It is not allowed to write this inside a plsql block. So exception handling for that is really tricky.
The usual way to solve that is to switch SQL*PLUS error handling off before the drop and on after the drop. Which is a nuisance.
typical example from certain installation scripts:
whenever sqlerror continue;
drop table abc;
whenever sqlerror exit failure;
create table abc ...
@CTrieb: Do you have another simple way how to solve that?
-
-
A nice idea, but not really necessary. You can write a simple error routine to solve this problem in actual ORACLE DB Version.
That workaround is really a pain if you're writing large migration scripts that might run several times depending on how you deploy things... Many things aren't really necessary. For instance, AVG(x) is not necessary because it can be calculated as SUM(x) / COUNT(*), but it's still super useful, no?
-
not required as it errors out
I get really anxious when my complex installation scripts have errors in them. I'd like to have no error at all or meaningful errors, no errors I can "safely ignore" (after manual and tedious introspection)
-
A few databases already support such syntax, including PostgreSQL and MySQL. Note that this isn't limited to only DROP TABLE statements, but it could work with pretty much any DDL statement:
- DROP <object> [ IF EXISTS ]
- ALTER <object> [ IF EXISTS ] ...
- ALTER <table> [ IF EXISTS ] ADD <column> [ IF NOT EXISTS ]
- ALTER <table> [ IF EXISTS ] DROP <column> [ IF EXISTS ]
- CREATE <object> [ IF NOT EXISTS ]
I would find this really really useful!