Home Database Mysql Tutorial DDL操作内部执行原理

DDL操作内部执行原理

Jun 07, 2016 pm 05:33 PM
o oracle database

执行完exp/imp之后,可以在imp的log文件中查看到相关表的建表语句,和与该表相关的其他数据库对象的ddl语句,如索引、触发器等。

Ddl操作实际上在内部被转化一系列的dml语句进行执行

跟踪ddl操作,查看Oracle后台数据字典自动执行的内容:

scott@ORCL>conn / as sysdba;

已连接。

sys@ORCL>alter session set events '10046trace name context forever,level 12';

会话已更改。

sys@ORCL>create table trace_ddl asselect * from dba_users;

表已创建。

sys@ORCL>select value from v$diag_infowhere; 

VALUE

----------------------------------------

d:\app\lenovo\diag\rdbms\orcl\orcl\trace

\orcl_ora_7460.trc

 

查看该文件中的内容:

 

首先记录的创建语句:

PARSING IN CURSOR #2 len=49 dep=0 uid=0oct=1 lid=0 tim=6439856921 hv=1016677043 ad='7ffbd8a2020' sqlid='6urykycy9khpm'

create table trace_ddl as select * fromdba_users

END OF STMT

 

向obj中增加记录的dml语句

PARSING IN CURSOR #4 len=216 dep=1 uid=0oct=2 lid=0 tim=6439892002 hv=714380553 ad='7ffc849c3c0' sqlid='4bjwv5sp99589'

insert intoobj$(owner#,name,namespace,obj#,type#,ctime,mtime,stime,status,remoteowner,linkname,subname,dataobj#,flags,oid$,spare1,spare2,spare3)values(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16,:17,:18)

END OF STMT

 

更新con$表的信息:
PARSING IN CURSOR #4 len=61 dep=1 uid=0 oct=6 lid=0 tim=6439918579hv=4246113160 ad='7ffbdca6628' sqlid='bajr90ryjd2w8'

update con$ set con#=:3,spare1=:4 whereowner#=:1 and name=:2

END OF STMT

 

增加段信息,向seg$表插入数据的语句:

PARSING IN CURSOR #4 len=259 dep=1 uid=0oct=2 lid=0 tim=6440002337 hv=1814305607 ad='7ffbd89ed80' sqlid='g7mt7ptq286u7'

insert into seg$(file#,block#,type#,ts#,blocks,extents,minexts,maxexts,extsize,extpct,user#,iniexts,lists,groups,cachehint,hwmincr,spare1, scanhint, bitmapranges) values(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16,DECODE(:17,0,NULL,:17),:18,:19)

END OF STMT

 

向col$增加字段信息:

PARSING IN CURSOR #4 len=453 dep=1 uid=0oct=2 lid=0 tim=6440042013 hv=224718466 ad='7ffbdca27b8' sqlid='60uw2vh6q9vn2'

insert intocol$(obj#,name,intcol#,segcol#,type#,length,precision#,scale,null$,offset,fixedstorage,segcollength,deflength,default$,col#,property,charsetid,charsetform,spare1,spare2,spare3)values(:1,:2,:3,:4,:5,:6,decode(:5,182/*DTYIYM*/,:7,183/*DTYIDS*/,:7,decode(:7,0,null,:7)),decode(:5,2,decode(:8,-127/*MAXSB1MINAL*/,null,:8),178,:8,179,:8,180,:8,181,:8,182,:8,183,:8,231,:8,null),:9,0,:10,:11,decode(:12,0,null,:12),:13,:14,:15,:16,:17,:18,:19,:20)

END OF STMT

 

Oracle通过将ddl解析为dml操作,并且将这些操作全部记录在数据字典中,通过将这些信息反向解析,,可以得到原始的创建语句

 

 

通过dbms_metadata可以得到原始的创建语句:

 

sys@ORCL>SELECTDBMS_METADATA.GET_DDL('TABLE','TRACE_DDL') FROM DUAL;

 

DBMS_METADATA.GET_DDL('TABLE','TRACE_DDL')

--------------------------------------------------------------------------------

 

 CREATE TABLE "SYS"."TRACE_DDL"

  (    "USERNAME" VARCHAR2(30)NOT NULL ENABLE,

      "USER_ID" NUMBER NOT NULL ENABLE,

      "PASSWORD" VARCHAR2(30),

      "ACCOUNT_STATUS" VARCHAR2(32) NOT NULL ENABLE,

      "LOCK_DATE" DATE,

      "EXPIRY_DATE" DATE,

      "DEFAULT_TABLESPACE" VARCHAR2(30) NOT NULL ENABLE,

      "TEMPORARY_TABLESPACE" VARCHAR2(30) NOT NULL ENABLE,

      "CREATED" DATE NOT NULL ENABLE,

      "PROFILE" VARCHAR2(30) NOT NULL ENABLE,

      "INITIAL_RSRC_CONSUMER_GROUP" VARCHAR2(30),

      "EXTERNAL_NAME" VARCHAR2(4000),

      "PASSWORD_VERSIONS"VARCHAR2(8),

      "EDITIONS_ENABLED" VARCHAR2(1),

      "AUTHENTICATION_TYPE" VARCHAR2(8)

  )PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING

 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645

 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULTFLASH_CACHE DEFAULT CELL_FLA

SH_CACHE DEFAULT)

 TABLESPACE "SYSTEM"

查看建表语句有另一个办法:

1. exp username/pwd@service_name file=?rows=n

2. imp username/pwd@service_name file=?show=y log=? tables=?

执行完exp/imp之后,可以在imp的log文件中查看到相关表的建表语句,和与该表相关的其他数据库对象的ddl语句,如索引、触发器等。

如果在imp的参数中以 fromuser, touser 来代替tables,会在log文件中看到该模式内所有对象的ddl语句。

相关阅读:

两台Oracle之间配置OGG-未配置同步DDL 

Oracle GoldenGate 11g单向DDL配置实战 

Oracle利用dbms_metadata.get_DDL查看DDL语句 

Oracle使用系统级触发器禁用DDL语句 

Oracle使用系统级触发器审计重要帐号的DDL语句 

linux

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

How to export oracle view How to export oracle view Apr 12, 2025 am 06:15 AM

Oracle views can be exported through the EXP utility: Log in to the Oracle database. Start the EXP utility, specifying the view name and export directory. Enter export parameters, including target mode, file format, and tablespace. Start exporting. Verify the export using the impdp utility.

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

MySQL vs. Other Databases: Comparing the Options MySQL vs. Other Databases: Comparing the Options Apr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

See all articles