Sunday, 8 June 2014

How to drop all tables and Views from a specific schema

How to drop all tables and Views from a specific schema

dropping all tables and views from a specific SCHEMA, SYSPROC.ADMIN_DROP_SCHEMA




Dropping all tables, views and the own schema:



CALL SYSPROC.ADMIN_DROP_SCHEMA('SCHNAME', NULL, 'ERRORSCHEMA', 'ERRORTABLE')
Replace  'SCHNAME' to schema name, example for DEPT schema :
CALL SYSPROC.ADMIN_DROP_SCHEMA('DEPT', NULL, 'ERRORSCHEMA', 'ERRORTABLE');


Dropping all tables



db2 -x "select 'drop table ' || rtrim(tabschema) || '.' || rtrim(tabname) || ' '  
       || ';'from syscat.tables where type = 'T' and tabschema='<schema_name>'"

Dropping all Views


db2 -x "select 'drop table ' || rtrim(tabschema) || '.' || rtrim(tabname) || ' '  
       || ';'from syscat.tables where type = 'V' and
       tabschema='<schema_name>'"

Dropping all Views and all Tables


db2 -x "select 'drop table ' || rtrim(tabschema) || '.' || 
          rtrim(tabname) || ' '  || ';'from syscat.tables where tabschema='<schema_name>'"

No comments:

Post a Comment