In MySQL it is pretty easy to drop a table if it exists already. In Oracle and Microsoft’s SQL Server it is a little more complicated. Today I want to present you the solutions for these two DBMS’.
MySQL:
DROP TABLE IF EXISTS [table_name]
Oracle:
BEGIN EXECUTE IMMEDIATE 'DROP TABLE [table_name]'; EXCEPTION WHEN OTHERS THEN NULL; END;
SQL Server:
IF EXISTS ( SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '[table_name]') DROP TABLE [table_name]
if exists (select * from sysobjects where id=object_id(N 'abc ')
and OBJECTPROPERTY(id, N 'IsUserTable ')=1)
drop table abc