ronisaha
4/20/2016 - 4:18 AM

ORACLE DDL GENERATOR

ORACLE DDL GENERATOR

select
case
  when b.table_name is null then
     'unindexed'
  else
     'indexed'
end as status,
  a.table_name      as table_name,
  a.constraint_name as fk_name,
 a.fk_columns      as fk_columns,
 b.index_name      as index_name,
 b.index_columns   as index_columns
from
(
  select 
   a.table_name,
  a.constraint_name,
  listagg(a.column_name, ',') within
group (order by a.position) fk_columns
from
  dba_cons_columns a,
  dba_constraints b
where
  a.constraint_name = b.constraint_name
and 
  b.constraint_type = 'R'
and 
  a.owner = '__OWNER_NAME__'
and 
  a.owner = b.owner
group by 
  a.table_name, 
  a.constraint_name
) a
,(
select 
  table_name,
  index_name,
  listagg(c.column_name, ',') within
group (order by c.column_position) index_columns
from
  dba_ind_columns c
where 
  c.index_owner = '__OWNER_NAME__'
group by
  table_name, 
  index_name
) b
where
  a.table_name = b.table_name(+)
and 
  b.index_columns(+) like a.fk_columns || '%'
order by 
  1 desc, 2;
CREATE USER __USER_NAME__
IDENTIFIED BY __USER_PASSWORD__
DEFAULT TABLESPACE __TABLE_SPACE_NAME_
TEMPORARY TABLESPACE temp
QUOTA UNLIMITED ON __TABLE_SPACE_NAME_;

GRANT CREATE SESSION TO __USER_NAME__;
GRANT CREATE TABLE TO __USER_NAME__;
GRANT CREATE VIEW TO __USER_NAME__;
GRANT CREATE TRIGGER TO __USER_NAME__;
GRANT CREATE PROCEDURE TO __USER_NAME__;
GRANT CREATE SEQUENCE TO __USER_NAME__;
GRANT CREATE SYNONYM TO __USER_NAME__;
GRANT CREATE ANY DIRECTORY TO __USER_NAME__;
-- `Enable` script generator.
-- Must be run before disable. This will ensure you donot enable any already disabled key while restoring

SELECT 
'ALTER TABLE ' || OWNER || '.' || table_name || ' enable CONSTRAINT ' || constraint_name || ';'
FROM dba_constraints WHERE constraint_type = 'R' and status = 'ENABLED' AND OWNER='__OWNER_NAME__';

--`Disable` script generator
select 
'ALTER TABLE ' || OWNER || '.' || table_name || ' disable CONSTRAINT ' || constraint_name || ';'
from dba_constraints where constraint_type = 'R' and status = 'ENABLED' AND OWNER='__OWNER_NAME__';