In SQL, we can use the DROP TABLE IF EXISTS
statement to drop a table only if it exists.
While it may seem obvious that we can only drop a table if it exists (i.e. we can’t drop a table that doesn’t exist), there’s a good reason for using this statement.
The reason we put an IF EXISTS
clause into a DROP TABLE
statement is to prevent any errors that would occur if the table doesn’t exist.