版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
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 becomes the last column.ALTER TABLE dept80ADD (job_id VARCHAR2(9);Table altered.Modifying a ColumnYou can change a
4、columns data type, size, and default value.A change to the default value affects only subsequent insertions to the table.ALTER TABLE dept80MODIFY(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
5、COLUMN 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
6、 OnlyAdding 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.Addin
7、g a ConstraintAdd 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 paren
8、t key 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 dept2AD
9、D CONSTRAINT 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
10、manager 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 Const
11、raintsExecute the DISABLE clause of the ALTER TABLE statement to deactivate an integrity constraint.Apply the CASCADE option to disable dependent integrity constraints.ALTER TABLE emp2DISABLE CONSTRAINT emp_dt_fk;Table altered.Enabling ConstraintsActivate an integrity constraint currently disabled i
12、n the table definition by using the ENABLE clause. A UNIQUE index is automatically created if you enable a UNIQUE key or PRIMARY KEY constraint.ALTER TABLEemp2ENABLE CONSTRAINT emp_dt_fk;Table altered.Notes OnlyCascading ConstraintsThe CASCADE CONSTRAINTS clause is used along with the DROP COLUMN cl
13、ause.he 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 D
14、ROP COLUMN employee_id CASCADE CONSTRAINTS;Table altered.ALTER TABLE test1DROP (pk, fk, col1) CASCADE CONSTRAINTS;Table altered.Overview of IndexesIndexes are created:Automatically PRIMARY KEY creation UNIQUE KEY creationManually CREATE INDEX statement CREATE TABLE statementCREATE INDEX with CREATE
15、TABLE Statement 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
16、_name_idxON 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 OnlyRemovin
17、g an IndexRemove 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;DRO
18、P TABLE PURGEDROP TABLE dept80 PURGE; The FLASHBACK TABLE Statement Repair tool for accidental table modifications Restores a table to an earlier point in time Benefits: Ease of use, availability, fast execution Performed in placeSyntax:FLASHBACK TABLEschema.table, schema.table .TO TIMESTAMP | SCN e
19、xpr ENABLE | DISABLE 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 th
20、at corresponds 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 DEL
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024-2030年中國城軌交通供電行業(yè)經(jīng)營模式分析與投資戰(zhàn)略規(guī)劃報告(版)
- 2024-2030年中國城中村改造建設(shè)行業(yè)發(fā)展趨勢及投融資規(guī)劃分析報告版
- 2024-2030年中國土地整治行業(yè)發(fā)展前景展望投資規(guī)劃分析報告
- 2024-2030年中國商用WiFi行業(yè)運營模式及未來發(fā)展規(guī)劃預(yù)測報告
- 2024-2030年中國呼叫中心行業(yè)經(jīng)營效益及投資盈利預(yù)測報告
- 2024-2030年中國雙向拉伸聚酯薄膜行業(yè)十三五需求及發(fā)展風(fēng)險研究報告
- 2024-2030年中國卡通及動漫玩具行業(yè)市場營銷模式及投資前景預(yù)測報告
- 2024-2030年中國十字軸行業(yè)運營模式及未來發(fā)展趨勢分析報告版
- 2024-2030年中國醫(yī)養(yǎng)結(jié)合模式行業(yè)發(fā)展預(yù)測及投資規(guī)劃分析報告版
- 2024-2030年中國利尿藥及脫水藥螺內(nèi)酯行業(yè)市場運營模式及未來發(fā)展動向預(yù)測報告
- 智慧醫(yī)聯(lián)體建設(shè)項目可行性研究報告
- 混合痔中醫(yī)護理 方案
- 2024年中考英語題型復(fù)習(xí):閱讀理解(含練習(xí)題及答案)
- 慢性病防治和健康生活知識講座
- 2024-2030年中國農(nóng)業(yè)機械產(chǎn)業(yè)發(fā)展格局與需求趨勢預(yù)測研究報告
- DZ∕T 0214-2020 礦產(chǎn)地質(zhì)勘查規(guī)范 銅、鉛、鋅、銀、鎳、鉬(正式版)
- HYT 087-2005 近岸海洋生態(tài)健康評價指南
- 人教版五年級美術(shù)學(xué)科試卷(附帶答案和考察要點解說)
- 士官生生涯規(guī)劃
- 人教部編版一年級道德與法治上冊第10課《吃飯有講究》精美課件
- (正式版)SHT 3158-2024 石油化工管殼式余熱鍋爐
評論
0/150
提交評論