سؤال

exec dbms_metadata.set_transform_param(DBMS_METADATA.SESSION_TRANSFORM, 'CONSTRAINTS_AS_ALTER', TRUE);

SELECT DBMS_METADATA.GET_DDL(object_type, object_name, owner) FROM all_OBJECTS WHERE  
OWNER = 'USERNAME' AND OBJECT_TYPE = 'TABLE';

When I run these commands, unfortunately I am getting the alter statements after each table. I would prefer to have the DDL generated for all of my tables, then have that followed by the alter statements to set up the constraints. Currently, the alter statement runs and fails for some tables because the table being referenced has not been created yet.

I have seen this command:

select dbms_metadata.get_ddl('CONSTRAINT',constraint_name) from user_constraints; 

But to use that wouldn't I have to somehow tell GET_DDL to not generate any constraints at all?

Is there some way to just make the tables created in the right order?

Thanks!

هل كانت مفيدة؟

المحلول

You can tell GET_DDL to not generate referential integrity constraints by running:

exec dbms_metadata.set_transform_param(DBMS_METADATA.SESSION_TRANSFORM, 'REF_CONSTRAINTS', FALSE);

Then run the constraint DDL, but only where constraint_type = 'R'. (You do not want to run all of the constraints separately, else you will need to generate the primary keys before the foreign keys, and run into the same dependency issue.)

See here for the list of transform parameters.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top