How do I get an Oracle SCHEMA as DDL scripts with DBMS_METADATA (and SCHEMA_EXPORT)

前端 未结 1 385
生来不讨喜
生来不讨喜 2020-12-19 05:41

I am having troubles to extract the DDL for a given schema with DBMS_METADATA, probably because my understanding of it is wrong.

Here\'s what I basically do:

相关标签:
1条回答
  • 2020-12-19 06:34

    Not so much an answer as an observation. It is technically possible (but probably daft in practice) to have circular references in constraints.

    create table blue (blue_id number primary key, val varchar2(10), red_id number);
    create table red (red_id number primary key, val varchar2(10), blue_id number);
    
    insert into blue values (1,'test',2);
    insert into red values (2,'test',1);
    
    alter table blue add constraint blue_fk foreign key (red_id) references red (red_id);
    alter table red add constraint red_fk foreign key (blue_id) references blue (blue_id);
    

    So I could understand if they decided that, because it is not necessarily always achievable, they wouldn't bother putting the objects in dependency order.

    As such, I'd leave the referential constraints out when tables are being created, then apply them as ALTERs after all the tables have been created.

    0 讨论(0)
提交回复
热议问题