Wednesday, September 3, 2014

Drop all objects from schema

DROP all objects in a SCHEMA


select 'drop '||object_type||' '|| object_name||';' from all_objects where owner='CCCNJ2'; 
select 'drop '||object_type||' '|| object_name||  DECODE(OBJECT_TYPE,'TABLE',' CASCADE CONSTRAINTS;',';') from user_objects


SELECT      'alter table '
         || owner
         || '.'
         || table_name
         || ' drop constraint '
         || constraint_name
         || ' cascade;' code
    FROM dba_constraints
   WHERE (constraint_type = 'R') AND (owner = UPPER ('&&enter_user_name'))
UNION
SELECT DISTINCT    'DROP '
                || object_type
                || ' '
                || owner
                || '.'
                || object_name
                || ';' code
           FROM dba_objects
          WHERE (object_type NOT IN ('INDEX'))
            AND (owner = UPPER ('&&enter_user_name'))
       ORDER BY code DESC;



select count(*) from all_objects where owner='Schema_name';





No comments:

Post a Comment