DBAsupport.com Forums - Powered by vBulletin
Results 1 to 8 of 8

Thread: Capture DDL

  1. #1
    Join Date
    Jan 2001
    Posts
    515

    Capture DDL

    Is there a quick way to create a DDL script for all the objects in a tablespace. I have a bad tablespace which I want to drop and recreate so I want all the DDL. It is Oracle 9.2.0.6. I have TOAD and DBArtisian at my disposal.

    Thanks.

  2. #2
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,684
    Hi.

    Try this:

    select dbms_metadata.get_ddl('TABLE',table_name, owner)
    from dba_tables
    where tablespace_name = 'USERS';

    and:

    select dbms_metadata.get_ddl('INDEX',index_name, owner)
    from dba_indexes
    where tablespace_name = 'USERS';


    If the output is truncated use "SET LONG X", where X is the maximum size you need to display.

    Cheers

    Tim...
    Tim...
    OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
    OCA PL/SQL Developer
    Oracle ACE Director
    My website: oracle-base.com
    My blog: oracle-base.com/blog

  3. #3
    Join Date
    Jan 2004
    Posts
    162
    Ditto. For example...
    Code:
    Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    
    SQL> SET LONG 100000;
    SQL> SELECT DBMS_METADATA.GET_DDL (
      2           segment_type, segment_name, owner)
      3  FROM   dba_segments
      4  WHERE  tablespace_name = 'PADDERS_DATA';
    
      CREATE TABLE "PADDERS"."DEPT"
       (    "DEPTNO" NUMBER(2,0),
            "DNAME" VARCHAR2(14),
            "LOC" VARCHAR2(13),
             CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO")
      USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "PADDERS_DATA"  ENABLE
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "PADDERS_DATA"
    
    
    
      CREATE TABLE "PADDERS"."EMP"
       (    "EMPNO" NUMBER(4,0),
            "ENAME" VARCHAR2(10),
            "JOB" VARCHAR2(9),
            "MGR" NUMBER(4,0),
            "HIREDATE" DATE,
            "SAL" NUMBER(7,2),
            "COMM" NUMBER(7,2),
            "DEPTNO" NUMBER(2,0),
            "HIREORDER" NUMBER,
             CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO")
      USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "PADDERS_DATA"  ENABLE,
             CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO")
              REFERENCES "PADDERS"."DEPT" ("DEPTNO") ENABLE
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "PADDERS_DATA"
    
    
    
      CREATE UNIQUE INDEX "PADDERS"."PK_DEPT" ON "PADDERS"."DEPT" ("DEPTNO")
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "PADDERS_DATA"
    
    
    
      CREATE UNIQUE INDEX "PADDERS"."PK_EMP" ON "PADDERS"."EMP" ("EMPNO")
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "PADDERS_DATA"
    
    
    
    4 rows selected.
    
    SQL>
    Be advised that DBMS_METADATA can be a bit slow.

  4. #4
    Join Date
    Nov 2002
    Location
    New Delhi, INDIA
    Posts
    1,796
    Another way. Get DDL Wizard.
    Amar
    "There is a difference between knowing the path and walking the path."

    Amar's Blog  Get Firefox!

  5. #5
    Join Date
    Jun 2000
    Location
    Madrid, Spain
    Posts
    7,447
    Just wondering if anyone used DataBee before?

  6. #6
    Join Date
    Nov 2002
    Location
    New Delhi, INDIA
    Posts
    1,796
    Yep I use it. It did help me during the development phase. I just take regular export with rows=n and then generate htmls for all schema using DDLWizard and deploy it on a webserver. This helps the developers to browse through the schema and see if object structures are correct or not.
    Amar
    "There is a difference between knowing the path and walking the path."

    Amar's Blog  Get Firefox!

  7. #7
    Join Date
    Jun 2000
    Location
    Madrid, Spain
    Posts
    7,447
    I mean DataBee not the DDL wizard!

  8. #8
    Join Date
    Nov 2002
    Location
    New Delhi, INDIA
    Posts
    1,796
    Amar
    "There is a difference between knowing the path and walking the path."

    Amar's Blog  Get Firefox!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width