3

I have lots of schemas and tables. I want to generate create script of all of my tables. I am using below statement and it is working pretty well.

SELECT DBMS_METADATA.GET_DDL('TABLE','table_name','schema') FROM DUAL

But this statement also generates all primary and foreign key scripts that belong to table. So, is there any way to not include primary and foreign keys in create table scripts

asked Apr 8, 2014 at 6:40
2
  • Why don't you want at least primary keys?! Commented Apr 8, 2014 at 7:24
  • I don't want primary keys. I want table script without primary keys because I have too many tables and it causes problems when inserting these tables to another location. Commented Apr 8, 2014 at 7:32

1 Answer 1

4

You could try the following:

set pagesize 0
set long 90000 
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',false);
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'CONSTRAINTS',false);
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'REF_CONSTRAINTS',false);
SELECT DBMS_METADATA.GET_DDL( 'TABLE','table_name','schema') FROM DUAL;

This should result in the DDL without any indexes and foreign keys.

Reference:

booyaa
2295 silver badges14 bronze badges
answered Apr 8, 2014 at 7:59
5
  • When I paste and copy above to TOAD it gave ORA-00900. But I changed your statement by adding "execute" statement to each proc, then it worked. Thanks Commented Apr 8, 2014 at 8:52
  • But I really don't understand why it did not work as your statement. Do you have any idea? Commented Apr 8, 2014 at 8:53
  • @osman they made an error, it doesn't work in query mode in sqldeveloper or in sqlplus. i've fixed the error, waiting on edit to be approved. Commented Apr 8, 2014 at 9:18
  • @booyaa I run this "SELECT * FROM ALL_OBJECTS WHERE OBJECT_TYPE = 'PROCEDURE' and object_name = 'SET_TRANSFORM_PARAM'" but got zero. I think I could find one? Commented Apr 8, 2014 at 9:30
  • sorry for the typo. Was on the run to a meeting. Yes, @booyaa is right. EXEC for each line is correct. Commented Apr 8, 2014 at 11:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.