How To Generate Create Table Script In Toad Oracle
< set echo off define schema=&1 This is not too bad. But with the plethora of table structural design options such as clustering, partitioning, index organized tables, external tables and such, it is clear that this little script would need thousands of lines of code plus more of the same for indexes and views. Generate DDL with dbms_metadata Prior to Oracle, getting table and index DDL was a time-consuming and tricky process. You could run the export utility with ROWS=NO, but the output was hard to re-use because of quoted strings. The only other option was to write complex dictionary scripts that might not work on complex objects such as IOT and nested tables. Punching DDL from the dictionary is very useful when you are migrating a system to a new platform and you want to pre-create the objects in a new tablespace so that you can import with IGNORE=Y. In Oraclewe have the exciting new dbms_metadata utility to display DDL directly from the data dictionary. Using this powerful utility, we can punch individual objects or an entire schema. Best of all, it is easy. You simply execute dbms_metadata. get_ddl. To punch off all table and indexes for the EMP table, we execute dbms_metadata. get_ddl, select from DUAL, and providing all required parameters. Here is the output. The only thing missing is the ending semicolons after each statement. Just for illustration, we show how a primary key can be punched as part of the table DDL or separately using the INDEX argument. Now we can modify the syntax to punch a whole schema. It us easily done by selecting dbms_metadata. get_ddl and specifying USER_TABLES and USER_INDEXES. : set pagesize 0 spool scott_schema.sql connect scott/tiger; SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name) SELECT DBMS_METADATA.GET_DDL('INDEX',u.index_name) spool off; So examine the exact same table generation process instead using the Oracle dbms_metadata PL/SQL package as shown in this SQL*Plus display table DDL script: set echo off EXECUTE DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'PRETTY',true); In just 12 short lines, a script is created to reverse engineer all the tables for a given schema and for every possible Oracle option or feature those tables use. Furthermore, now the task of keeping such a script current is now on Oracle?s shoulders. So even if Oracle adds new table options or parameters like extends or changes to the CREATE/ALTER table syntax, the script is not affected. Additionally, this DDL generation script can be extended to change or add additional objects types because it is very straightforward and easy. For example, if one wanted to switch to or add indexes, just substitute or add this command. Now compare the actual table CREATE TABLE DDL generated from the new_generate_table_ddl.sql SQL*Plus script, shown next, to the earlier output from the old_generate_table_ddl.sql SQL*Plus script. Note that check constraints, primary keys and unique keys have been picked up along with their storage clauses. Furthermore, even the table storage clause is more accurate with items such as NOCOMPRESS, NOLOGGING and BUFFER_POOL now covered. You can use expdp to export only the table, index and constraint definitions for a table or a group of tables. Here is the export syntax to only extract the table definitions using the metadata_only argument: $expdp scott/tiger full=y content=METADATA_ONLY exclude=STATISTICS |
How To Generate Create Table Script In Toad Oracle
Source: http://www.dba-oracle.com/oracle_tips_dbms_metadata.htm
Posted by: meaghercasere1999.blogspot.com

0 Response to "How To Generate Create Table Script In Toad Oracle"
Post a Comment