DB2 Drop table if exists equivalent

Roman Iuvshin picture Roman Iuvshin · Nov 25, 2011 · Viewed 29.4k times · Source

I need to drop a DB2 table if it exists, or drop and ignore errors.

Answer

deltascience picture deltascience · Apr 3, 2017

Try this one:

IF EXISTS (SELECT name FROM sysibm.systables WHERE name = 'tab_name') THEN
DROP TABLE tab_name;END IF;