Oracle 8 Database Administration volume 2 instruction guide phần 3 doc

34 250 0
Oracle 8 Database Administration volume 2 instruction guide phần 3 doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Oracle8: Database Administration 14-27 . Maintaining Constraints and Triggers By default, a trigger is enabled when created. Disabling Triggers Disabling a trigger may be necessary in the following conditions: • An object that the trigger references is not available, but the DML activity on the table cannot be stopped. • To speed up a large data load on the table that has the trigger. Use the following command to disable a trigger: ALTER TRIGGER [ schema. ]trigger DISABLE Enabling Triggers Use the following command to enable a trigger: ALTER TRIGGER [ schema. ]trigger ENABLE What follows is the syntax for enabling or disabling all triggers in a table: ALTER TABLE [ schema. ]table { DISABLE | ENABLE } ALL TRIGGERS 14-16 Copyright  Oracle Corporation, 1998. All rights reserved. Disabling and Enabling Triggers • Use ALTER TRIGGER to disable or enable one trigger. • Use ALTER TABLE to disable or enable all triggers. ALTER TRIGGER scott.emp_conv_ln DISABLE; ALTER TABLE scott.employees ENABLE ALL TRIGGERS; 14-28 Oracle8: Database Administration . Lesson 14: Maintaining Data Integrity Constraints may be dropped when: • They are no longer necessary. • They need to be modified but because they cannot be modified directly, they must be dropped and added. Syntax Use the following command to drop a constraint: ALTER TABLE [ schema. ] table DROP {CONSTRAINT constraint | PRIMARY KEY | UNIQUE ( column [, column ] ) } [ CASCADE ] Note • Use the CASCADE option to drop any constraint that is referenced by a foreign key. • When a primary key or a unique constraint is dropped, any associated unique index is also dropped. • If a primary key or unique constraint is implemented using a nonunique index, the associated index is not dropped, and must be dropped manually if not required. 14-17 Copyright  Oracle Corporation, 1998. All rights reserved. Dropping Constraints • Drop constraints using this command: • Drop a table and any referencing foreign key using this command: ALTER TABLE scott.employees DROP CONSTRAINT emp_ln_uk; DROP TABLE departments CASCADE CONSTRAINTS; Oracle8: Database Administration 14-29 . Maintaining Constraints and Triggers Dropping a Parent Table Tables that are referenced by a foreign key can only be dropped if the foreign key is dropped. This can be achieved using the following command: DROP [ schema .] table CASCADE CONSTRAINTS This may be necessary if the parent table needs to be reorganized. 14-30 Oracle8: Database Administration . Lesson 14: Maintaining Data Integrity Use the following command to drop a trigger that is no longer required: DROP TRIGGER [ schema. ] trigger 14-18 Copyright  Oracle Corporation, 1998. All rights reserved. Dropping Triggers DROP TRIGGER scott.audit_dept; Oracle8: Database Administration 14-31 . Getting Constraint and Trigger Information Getting Constraint and Trigger Information Constraints and Their Status Use the following query to obtain the names, types, and status of all constraints on SCOTT’s EMP table: SVRMGR> SELECT constraint_name, constraint_type, deferrable, 2> deferred, validated 3> FROM dba_constraints 4> WHERE owner='SCOTT' 5> AND table_name='EMPLOYEES'; CONSTRAINT_NAME C DEFERRABLE DEFERRED VALIDATED - EMP_DEPT_FK R DEFERRABLE DEFERRED VALIDATED EMP_PK P DEFERRABLE IMMEDIATE VALIDATED SYS_C00565 C NOT DEFERRABLE IMMEDIATE VALIDATED 3 rows selected. 14 - 19 Co p y ri g h t  O r ac l e Co rp o r at i o n , 1 998 . All ri g h ts r ese rv ed . Getting Constraint Information DBA_CONSTRAINTS OWNER CONSTRAINT_NAME CONSTRAINT_TYPE TABLE_NAME SEARCH_CONDITION R_OWNER R_CONSTRAINT_NAME DELETE_RULE STATUS DEFERRABLE DEFERRED VALIDATED GENERATED BAD LAST_CHANGE DBA_CONS_COLUMNS OWNER CONSTRAINT_NAME TABLE_NAME COLUMN_NAME POSITION 14-32 Oracle8: Database Administration . Lesson 14: Maintaining Data Integrity The following table shows the columns in DBA_CONSTRAINTS view that are not self-evident. Columns in Constraints To get the columns in the constraints on SCOTT’s EMP table, use the following query: SVRMGR> SELECT c.constraint_name, c.constraint_type, 2> cc.column_name 3> FROM dba_constraints c, dba_cons_columns cc 4> WHERE c.owner='SCOTT' 5> AND c.table_name='EMPLOYEES' 6> AND c.owner = cc.owner 7> AND c.constraint_name = cc.constraint_name 8> ORDER BY cc.position; CONSTRAINT_NAME C COLUMN_NAME - EMP_DEPT_FK R DEPTNO EMP_PK P EMPNO SYS_C00565 C LAST_NAME 3 rows selected. Name Description CONSTRAINT_TYPE The type of constraint is P if Primary key, U if Unique, R if Foreign key, or C if Check constraint. NOT NULL constraints are stored as check constraints. SEARCH_CONDITION Shows the condition specified for a check constraint R_OWNER R_CONSTRAINT_NAME Define the owner and name of the referenced constraint for foreign keys GENERATED Indicates whether the constraint name is system generated (Valid values are ‘USER NAME’ and ‘GENERATED NAME’.) BAD Indicates that the constraint is to be rewritten to avoid such situations as Year 2000 problems (This might happen because earlier releases of Oracle allowed 2-digit years to be specified in check constraints.) LAST_CHANGE The date when the constraint was last enabled or disabled Oracle8: Database Administration 14-33 . Getting Constraint and Trigger Information Finding Primary Key–Foreign Key Relationships To find foreign keys on SCOTT’s EMP table and the parent constraints, use the following query: SVRMGR> SELECT c.constraint_name AS "Foreign Key", 2> p.constraint_name AS "Referenced Key", 3> p.constraint_type, 4> p.owner, 5> p.table_name 6> FROM dba_constraints c, dba_constraints p 7> WHERE c.owner='SCOTT' 8> AND c.table_name='EMPLOYEES' 9> AND c.constraint_type='R' 10> AND c.r_owner=p.owner 11> AND c.r_constraint_name = p.constraint_name; Foreign Key Referenced Key C OWNER TABLE_NAME - EMP_DEPT_FK DEPT_PK P SCOTT DEPARTMENTS 1 row selected. 14-34 Oracle8: Database Administration . Lesson 14: Maintaining Data Integrity 14-20 Copyright  Oracle Corporation, 1998. All rights reserved. Getting Information on Triggers DBA_TRIGGERS OWNER TRIGGER_NAME TRIGGER_TYPE TRIGGERING_EVENT TABLE_OWNER TABLE_NAME STATUS DESCRIPTION TRIGGER_BODY DBA_TRIGGER_COLS TRIGGER_OWNER TRIGGER_NAME TABLE_OWNER TABLE_NAME COLUMN_NAME DBA_OBJECTS OWNER OBJECT_NAME OBJECT_TYPE STATUS Oracle8: Database Administration 14-35 . Getting Constraint and Trigger Information Triggers and Trigger Columns To find the names of all triggers on SCOTT’s EMP table, and the columns if any, in the UPDATE OF clause, use the following query: SVRMGR> SELECT t.owner, t.trigger_name, t.trigger_type, 2 t.triggering_event, t.status, 3 c.column_name, o.status as "VALIDITY" 4 FROM dba_triggers t, dba_trigger_cols c, 5 dba_objects o 6 WHERE t.owner = c.trigger_owner (+) 7 AND t.trigger_name = c.trigger_name (+) 8 AND t.owner = o.owner 9 AND t.trigger_name = o.object_name 10 AND o.object_type = 'TRIGGER' 11 AND t.table_owner = 'SCOTT' 12 AND t.table_name = 'EMPLOYEES'; OWNER RIGGER_NAME TRIGGER_TYPE TRIGGERING_EVENT STATUS COLUMN_NAME VALIDITY SCOTT EMP_CONV_LN BEFORE STATEMENT INSERT OR UPDATE ENABLED LAST_NAME VALID SCOTT T1 BEFORE STATEMENT UPDATE ENABLED EMPNO INVALID 2 rows selected. 14-36 Oracle8: Database Administration . Lesson 14: Maintaining Data Integrity Summary 14-21 Copyright  Oracle Corporation, 1998. All rights reserved. Summary • Implementing constraints and triggers • Using appropriate strategy for creating and maintaining constraints [...]... 101 1 02 1 02 1 02 101 101 PROD QTY -A41 02 20 A2091 11 G 7 83 0 20 N9 587 26 A5675 19 W 0 82 4 10 ORD_NO -101 1 02 ORD_DT CUST_CD 05-JAN-97 R01 07-JAN-97 N45 Unclustered ORD and ITEM tables 15-4 Cluster Key (ORD_NO) CUST_CD 101 ORD_DT 05-JAN-97 R01 PROD QTY A41 02 20 A5675 19 W 0 82 4 10 CUST_CD 1 02 ORD_DT 07-JAN-97 N45 QTY PROD A2091 11 G 7 83 0 20 N9 587 26 Clustered ORD and ITEM tables Copyright © Oracle. .. Oracle8 : Database Administration 14 -37 Lesson 14: Maintaining Data Integrity 14- 38 Oracle8 : Database Administration 15 Using Clusters and Index-Organized Tables Lesson 15: Using Clusters and Index-Organized Tables Instructor Note Topic Lecture Timing 45 minutes Practice 15 minutes Total 60 minutes 15 -2 Oracle8 : Database. .. c, dba_tab_columns cc 8> WHERE c.owner = cc.owner 9> AND c.cluster_name = cc.table_name 10> AND c owner= 'SCOTT'; CLUSTER_NAME CLUST KEY_SIZE COLUMN_NAME DATA_TYPE COLSIZE - OFF_CLU HASH 500 COUNTRY VARCHAR2 2 OFF_CLU HASH 500 POSTCODE VARCHAR2 8 ORD_CLU INDEX 30 0 ORD_NO NUMBER 3, 0 3 rows selected Oracle8 : Database Administration 15 -21 Lesson 15: Using Clusters... later in this section 15-14 Oracle8 : Database Administration Creating Clusters Parameters Specific to Hash Clusters • HASHKEYS: Number of key values • HASH IS: Optional user-defined hash function Key 21 Key 11 Key 1 Key 12 Key 2 Key 3 Preallocated blocks 15-10 Key 22 Overflow block Copyright © Oracle Corporation, 19 98 All rights reserved HASHKEYS The keyword HASHKEYS... Oracle8 : Database Administration 15-11 Lesson 15: Using Clusters and Index-Organized Tables Creating Hash Clusters 1 Create a cluster CREATE CLUSTER scott.off_clu (country VARCHAR2 (2) ,postcode VARCHAR2 (8) ) SIZE 500 HASHKEYS 1000 TABLESPACE DATA01 STORAGE(INITIAL 5M NEXT 5M PCTINCREASE 0); 2 Create tables in a cluster CREATE TABLE scott.office( office_cd NUMBER (3) , cost_ctr... tables in a cluster CREATE TABLE scott.office( office_cd NUMBER (3) , cost_ctr NUMBER (3) , country VARCHAR2 (2) , postcode VARCHAR2 (8) ) CLUSTER scott.off_clu(country,postcode); 15 -8 Copyright © Oracle Corporation, 19 98 All rights reserved To create a hash cluster and place tables in it, follow these steps: 1 Create the cluster 2 Create the tables Syntax The command for creating a hash cluster is similar to... 15- 12 Oracle8 : Database Administration Creating Clusters The HASHKEYS clause indicates that the cluster is a hash cluster The Oracle server uses the next higher prime number as the number of possible cluster key values The optional clause HASH IS can be used to specify a user defined hash function, expression OEM 1 Use Oracle Schema Manager 2 Choose Object—>Create 3 Select Cluster... PCTINCREASE 0); 15-6 Copyright © Oracle Corporation, 19 98 All rights reserved Creating Index Clusters 3 Create tables in the cluster CREATE TABLE scott.ord (ord_no NUMBER (3) CONSTRAINT ord_pk PRIMARY KEY, ord_dt DATE, cust_cd VARCHAR2 (3) ) CLUSTER scott.ord_clu(ord_no); CREATE TABLE scott.item (ord_no NUMBER (3) CONSTRAINT item_ord_fk REFERENCES scott.ord, prod VARCHAR2(5), qty NUMBER (3) , CONSTRAINT item_pk PRIMARY... 15 -2 Oracle8 : Database Administration Objectives Objectives Objectives • Creating and maintaining clusters • Using index-organized tables • Retrieving information about clusters and tables from the data dictionary 15 -2 Copyright © Oracle Corporation, 19 98 All rights reserved Oracle8 : Database Administration 15 -3 Lesson 15: Using Clusters and Index-Organized... block The Oracle server uses this value to estimate the maximum number of key values that can be accommodated in each block of the cluster In the example, SIZE is set to 20 0 For a block size of 20 48, after allowing for the header, about 1900 bytes are available in the block for storing data Therefore, a block can accommodate a maximum of 9 key values 15-10 Oracle8 : Database Administration . 07-JAN-97 N45 PROD QTY A2091 11 G 7 83 0 20 N9 587 26 Unclustered ORD and ITEM tables ORD_NO PROD QTY 101 A41 02 20 1 02 A2091 11 1 02 G 7 83 0 20 1 02 N9 587 26 101 A5675 19 101 W 0 82 4 10 ORD_NO ORD_DT. and functions None 14- 38 Oracle8 : Database Administration . Lesson 14: Maintaining Data Integrity 15 Using Clusters and Index-Organized Tables 15 -2 Oracle8 : Database Administration . Lesson. ENABLED EMPNO INVALID 2 rows selected. 14 -36 Oracle8 : Database Administration . Lesson 14: Maintaining Data Integrity Summary 14 -21 Copyright  Oracle Corporation, 19 98. All rights reserved. Summary •

Ngày đăng: 08/08/2014, 20:21

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan