Wednesday, June 25, 2008

Get DDL of all tables and indexes in a Schema

DBMS_METADATA package can be conveniently used to get the DDL of all tables and indexes in a schema. The sample syntax is as follows:



set pagesize 0
set long 90000
set feedback off
set echo off
spool ddl.txt
SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name, 'MY_SCHEMA') || '/'
FROM dba_tables u
where owner='MY_SCHEMA';


SELECT DBMS_METADATA.GET_DDL('INDEX',u.index_name, 'MY_SCHEMA') || '/'
FROM dba_INDEXES u
where owner='MY_SCHEMA';
spool off;

No comments: