付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Manage Schema Objects ObjectivesAfter completing this lesson, you should be able to do the following: Add constraintsCreate indexesCreate indexes using the CREATE TABLE statementCreating function-based indexesDrop columns and set column UNUSEDPerform FLASHBACK operationsCreate and use external table
2、sThe ALTER TABLE StatementUse the ALTER TABLE statement to:Add a new columnModify an existing columnDefine a default value for the new columnDrop a columnThe ALTER TABLE StatementUse the ALTER TABLE statement to add, modify, or drop columns.ALTER TABLE tableADD (column datatype DEFAULT expr , column
3、 datatype.);ALTER TABLE tableMODIFY (column datatype DEFAULT expr , column datatype.);ALTER TABLE tableDROP (column);Adding a ColumnYou use the ADD clause to add columns.The new column es the last column.ALTER TABLE dept80ADD (job_id VARCHAR2(9);Table altered.Modifying a ColumnYou can change a colum
4、ns data type, size, and default value.A change to the default value affects only subsequent insertions to the table.ALTER TABLEdept80MODIFY(last_name VARCHAR2(30);Table altered.Dropping a ColumnUse the DROP COLUMN clause to drop columns you no longer need from the table.ALTER TABLE dept80DROP COLUMN
5、 job_id; Table altered.ALTER TABLE SET UNUSED();ALTER TABLE SET UNUSED COLUMN ;The SET UNUSED OptionYou use the SET UNUSED option to mark one or more columns as unused.You use the DROP UNUSED COLUMNS option to remove the columns that are marked as unused.ORALTER TABLE DROP UNUSED COLUMNS;Notes OnlyA
6、dding a Constraint SyntaxUse the ALTER TABLE statement to:Add or drop a constraint, but not modify its structureEnable or disable constraintsAdd a NOT NULL constraint by using the MODIFY clauseALTER TABLE ADD CONSTRAINT type ();ALTER TABLE emp2modify employee_id Primary Key;Table altered.Adding a Co
7、nstraintAdd a FOREIGN KEY constraint to the EMP2 table indicating that a manager must already exist as a valid employee in the EMP2 table.ALTER TABLE emp2ADD CONSTRAINT emp_mgr_fk FOREIGN KEY(manager_id) REFERENCES emp2(employee_id);Table altered.ON DELETE CASCADEDelete child rows when a parent key
8、is deleted.ALTER TABLE Emp2 ADD CONSTRAINT emp_dt_fk FOREIGN KEY (Department_id) REFERENCES departments ON DELETE CASCADE); Table altered.Deferring ConstraintsConstraints can have the following attributes:DEFERRABLE or NOT DEFERRABLE INITIALLY DEFERRED or INITIALLY IMMEDIATEALTER TABLE dept2ADD CONS
9、TRAINT dept2_id_pk PRIMARY KEY (department_id)DEFERRABLE INITIALLY DEFERREDALTER SESSION SET CONSTRAINTS= IMMEDIATESET CONSTRAINTS dept2_id_pk IMMEDIATEDeferring constraint on creationChanging all constraints for a sessionChanging a specific constraint attributeDropping a ConstraintRemove the manage
10、r constraint from the EMP2 table.Remove the PRIMARY KEY constraint on the DEPT2 table and drop the associated FOREIGN KEY constraint on the EMP2.DEPARTMENT_ID column.ALTER TABLE emp2DROP CONSTRAINT emp_mgr_fk;Table altered.ALTER TABLE dept2DROP PRIMARY KEY CASCADE;Table altered.Disabling Constraints
11、Execute the DISABLE clause of the ALTER TABLE statement to deactivate an integrity constraint.Apply the CASCADE option to disable dependent integrity constraints.ALTER TABLEemp2DISABLE CONSTRAINT emp_dt_fk;Table altered.Enabling ConstraintsActivate an integrity constraint currently disabled in the t
12、able definition by using the ENABLE clause. A UNIQUE index is automatically created if you enable a UNIQUE key or PRIMARY KEY constraint.ALTER TABLEemp2ENABLE CONSTRAINTemp_dt_fk;Table altered.Notes OnlyCascading ConstraintsThe CASCADE CONSTRAINTS clause is used along with the DROP COLUMN clause.The
13、 CASCADE CONSTRAINTS clause drops all referential integrity constraints that refer to the primary and unique keys defined on the dropped columns.The CASCADE CONSTRAINTS clause also drops all multicolumn constraints defined on the dropped columns.Cascading ConstraintsExample:ALTER TABLE emp2 DROP COL
14、UMN employee_id CASCADE CONSTRAINTS;Table altered.ALTER TABLE test1DROP (pk, fk, col1) CASCADE CONSTRAINTS;Table altered.Overview of IndexesIndexes are created:AutomaticallyPRIMARY KEY creationUNIQUE KEY creationManuallyCREATE INDEX statementCREATE TABLE statementCREATE INDEX with CREATE TABLE State
15、ment CREATE TABLE NEW_EMP(employee_id NUMBER(6) PRIMARY KEY USING INDEX (CREATE INDEX emp_id_idx ON NEW_EMP(employee_id),first_name VARCHAR2(20),last_name VARCHAR2(25);Table created.SELECT INDEX_NAME, TABLE_NAME FROM USER_INDEXESWHERE TABLE_NAME = NEW_EMP;Notes OnlyCREATE INDEX upper_dept_name_idxON
16、 dept2(UPPER(department_name);Index created.SELECT *FROM dept2WHERE UPPER(department_name) = SALES;Function-Based IndexesA function-based index is based on expressions. The index expression is built from table columns, constants, SQL functions, and user-defined functions.Notes OnlyRemoving an IndexR
17、emove an index from the data dictionary by using the DROP INDEX command.Remove the UPPER_DEPT_NAME_IDX index from the data dictionary.To drop an index, you must be the owner of the index or have the DROP ANY INDEX privilege.DROP INDEX upper_dept_name_idx;Index dropped.DROP INDEX index;DROP TABLE PUR
18、GEDROP TABLE dept80 PURGE; The FLASHBACK TABLE Statement Repair tool for accidental table modificationsRestores a table to an earlier point in timeBenefits: Ease of use, availability, fast executionPerformed in placeSyntax:FLASHBACK TABLEschema.table, schema.table .TO TIMESTAMP | SCN expr ENABLE | D
19、ISABLE TRIGGERS ;The FLASHBACK TABLE Statement DROP TABLE emp2;Table droppedFLASHBACK TABLE emp2 TO BEFORE DROP;Flashback complete SELECT original_name, operation, droptime, FROM recyclebin;External TablesNotes onlyCreating a Directory for the External TableCreate a DIRECTORY object that corresponds
20、 to the directory on the file system where the external data source resides.CREATE OR REPLACE DIRECTORY emp_dir AS /emp_dir; GRANT READ ON DIRECTORY emp_dir TO hr;Notes OnlyCreating an External TableCREATE TABLE ( , ) ORGANIZATION EXTERNAL (TYPE DEFAULT DIRECTORY ACCESS PARAMETERS ( ) ) LOCATION () ) REJECT LIMIT 0 | | UNLIMITED; Notes OnlyCreating an External Table Using ORACLE_LOADERCREATE TABLE oldemp ( fname char(25), lname CHAR(25) ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY emp_dir ACCESS PARAMETERS (RECORDS DELI
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 创伤急救护理中的疼痛管理
- 医联体模式下围手术期JCI标准的协同管理
- 医联体协同发展:提升基层患者满意度
- 医疗资源协同
- 2025年老年人紧急救援培训
- 医疗质量第三方评价与患者满意度对比
- 2025年博物馆安全培训课件
- 乙型流感护理中的患者权利
- 传染病护理知识更新
- 巧克力囊肿患者的心理压力管理与缓解
- 12345政务热线招录工作人员的笔试备考题库及答案详解一套
- 医院培训课件:《鼻胃管置入及拔出术》
- DBJT 13-505-2025 福建省既有钢结构检测与鉴定技术标准
- 2025年通辽单招题库及答案护理
- 2025至2030中国真空(泵和阀门)行业项目调研及市场前景预测评估报告
- 机场值机考试试题及答案
- 物流保供异常管理办法
- 2025年高等教育工学类自考-02141计算机网络技术历年参考题库含答案解析(5套典型考题)
- 家校沟通策略与实施方法
- 物业工程主管岗位面试问题及答案
- 军人俱乐部管理办法
评论
0/150
提交评论