Get table and index DDL in the easy way(轉)
Get table and index DDL the easy way
|
Prior to Oracle9i, 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 Oracle9i we 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. set heading off;set echo off;Set pages 999;set long 90000;spool ddl_list.sqlselect dbms_metadata.get_ddl('TABLE','DEPT','SCOTT') from dual;select dbms_metadata.get_ddl('INDEX','DEPT_IDX','SCOTT') from dual;spool off;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. CREATE TABLE "SCOTT"."DEPT"( "DEPTNO" NUMBER(2,0),"DNAME" VARCHAR2(14),"LOC" VARCHAR2(13),CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO")USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255STORAGE(INITIAL 12288 NEXT 12288 MINEXTENTS 1 MAXEXTENTS 249 PCTINCREASE 50FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "SYSTEM" ENABLE) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 LOGGINGSTORAGE(INITIAL 12288 NEXT 12288 MINEXTENTS 1 MAXEXTENTS 249 PCTINCREASE 50FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "SYSTEM"CREATE UNIQUE INDEX "SCOTT"."DEPT_IDX" ON "SCOTT"."DEPT" ("DNAME")FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "SYSTEM"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; |
When you have foreign keys (“references” constraints), it would be nice to punch the table DDL in their proper order for re-loading into another database. If you do not order the table, a table may be added that references another table that has not yet been added. Making this change would involve adding a WHERE clause that queries dba_constraints and dba_cons_columns to determine the proper table order. |
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/421207/viewspace-1004420/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- index table (IOT)Index
- nohup not working, another way to get the script run in the background
- dbms_metadata.get_ddl
- partition table and partition indexIndex
- TABLE size (including table,index,lob,lobindex)Index
- 利用dbms_metadata.get_ddl檢視DDL語句
- 用dbms_metadata.get_ddl獲取ddl語句
- DBMS_METADATE.GET_DDL獲取物件DDL指令碼物件指令碼
- alter table using indexIndex
- Oracle利用dbms_metadata.get_ddl檢視DDL語句Oracle
- dbms_metadata.get_ddl的妙用
- dbms_metadata.get_ddl學習
- dbms_metadata.get_ddl的使用
- 關於dbms_metadata.get_ddl
- dbms_metadata.get_ddl的用法
- DBMS_METADATA.GET_DDL獲取使用者ddl指令碼指令碼
- 使用DBMS_METADATA.GET_DDL獲取物件的DDL指令碼物件指令碼
- 收集full table / index scan sqlIndexSQL
- 查詢使用表空間的TABLE,INDEX,INDEX SUBPARTITIONIndex
- CREATE INDEX index1 ON table1(col1)Index
- 資源路由resource index 不是get路由Index
- dbms_metadata.get_ddl詳細用法
- 資料庫表--index organized table資料庫IndexZed
- 資料庫表--index clustered table資料庫Index
- Oracle Index-organized table (IOT)概述OracleIndexZed
- 索引組織表(Index Organizied Table)索引Index
- oracle使用dbms_metadata.get_ddl包檢視DDL語句定義Oracle
- 通過DBMS_METADATA.GET_DDL包獲得相關物件ddl語句物件
- table/index/LOBINDEX遷移表空間Index
- 簡述Oracle IOT(Index Organized Table)(上)OracleIndexZed
- 簡述Oracle IOT(Index Organized Table)(下)OracleIndexZed
- 簡述Oracle IOT(Index Organized Table)(中)OracleIndexZed
- 索引組織表(index organized table ,IOT)索引IndexZed
- Index-Organized Table Applications (236)IndexZedAPP
- 資料庫 sqlite3_get_table,sqlite3_free_table資料庫SQLite
- 從system/sysaux空間轉移TABLE&Index到其它表空間UXIndex
- (轉)索引掃描還是全表掃描(Index Scan Or Full Table Scan)索引Index
- 轉)索引掃描還是全表掃描(Index Scan Or Full Table Scan)索引Index