Integrity 7. 1 CSE2316/3316 Database Management Systems Database Integrity.

Slides:



Advertisements
Similar presentations
Data Definition and Integrity Constraints
Advertisements

The Relational Model. Introduction Introduced by Ted Codd at IBM Research in 1970 The relational model represents data in the form of table. Main concept.
Fall 2005 ICS184/EECS116 – Notes 08 1 ICS 184/EECS116: Introduction to Data Management Lecture Note 8 SQL: Structured Query Language -- DDL.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Triggers. Triggers: Motivation Assertions are powerful, but the DBMS often can’t tell when they need to be checked. Attribute- and tuple-based checks.
Triggers The different types of integrity constraints discussed so far provide a declarative mechanism to associate “simple” conditions with a table such.
Constraints We have discussed three types of integrity constraints: primary keys, not null constraints, and unique constraints. CREATE TABLE Movies ( title.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
Oracle8 - The Complete Reference. Koch & Loney1 Chapter 17 Creating, Dropping, and Altering Tables and Views Presented by Victor Matos.
Triggers.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Oracle Data Definition Language (DDL)
Chapter 6: Integrity and Security Thomas Nikl 19 October, 2004 CS157B.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
1 Copyright © 2006, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
PCLec08 / 1 8. Integrity This session will be directed at the many and various aspects of ‘Integrity’ Integrity processes are included to ensure that the.
In Oracle.  A PL/SQL block stored in the database and fired in response to a specified event ◦ DML statements : insert, update, delete ◦ DDL statements.
10 Creating and Managing Tables Objectives At the end of this lesson, you will be able to: Describe the main database objects Create tables Describe.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
Session 2: SQL (A): Parts 1 and 2 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Fall 2001Database Systems1 Triggers Assertions –Assertions describe rules that should hold for a given database. –An assertion is checked anytime a table.
Advanced SQL: Triggers & Assertions
11-1 Copyright  Oracle Corporation, All rights reserved. What Are Constraints? Constraints enforce rules at the table level. Constraints prevent.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Copyright  Oracle Corporation, All rights reserved. 11 Including Constraints.
Copyright  Oracle Corporation, All rights reserved. Introduction.
7 1 Constraints & Triggers Chapter Constraints and triggers? Constraints: Certain properties that the DBMS is required to enforce –E.g. primary.
Copyright  Oracle Corporation, All rights reserved. 4 Introduction.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
SQL: Part 1 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram. Not for commercial.
9 Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Schema Objects.
Objectives Database triggers and syntax
INCLUDING CONSTRAINTS lecture5. Outlines  What are Constraints ?  Constraint Guidelines  Defining Constraint  NOT NULL constraint  Unique constraint.
11 Including Constraints Objectives At the end of this lesson, you will be able to: Describe constraints Create and maintain constraints At the.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 9 Database Triggers.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 1.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Session 1 Module 1: Introduction to Data Integrity
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Relational State Assertions These slides.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Including Constraints. What Are Constraints? Constraints enforce rules at the table level. You can use constraints to do the following: – Enforce rules.
Copyright س Oracle Corporation, All rights reserved. 12 Creating Views.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Murali Mani Constraints. Murali Mani Keys: Primary keys and unique CREATE TABLE Student ( sNum int, sName varchar (20), dept char (2), CONSTRAINT key.
SQL Statements SELECT INSERTUPDATEDELETECREATEALTERDROPRENAMETRUNCATECOMMITROLLBACKSAVEPOINTGRANTREVOKE Data Retrieval Language (DRL) Data Retrieval Language.
1 Constraints and Triggers in SQL. 2 Constraints are conditions that must hold on all valid relation instances SQL2 provides a variety of techniques for.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Database Constraints Ashima Wadhwa. Database Constraints Database constraints are restrictions on the contents of the database or on database operations.
Including Constraints
Creating Database Triggers
Introduction to Database Systems, CS420
Database Systems Instructor Name: Lecture-12.
Manipulating Data Schedule: Timing Topic 40 minutes Lecture
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
Prof. Arfaoui. COM390 Chapter 9
Including Constraints
Presentation transcript:

Integrity 7. 1 CSE2316/3316 Database Management Systems Database Integrity

Integrity 7. 2 Integrity Components of a Data Model – Structure – Operators – Integrity

Integrity 7. 3 Dangers to Data A DBMS must protect data from several dangers. - Accidents (programming errors and miskeying) :these are integrity issues. - Malicious Use : A security issue. - Hardware and Software Failures :these are concurrency and restart issues.

Integrity 7. 4 Definitions of Integrity Data integrity requires the database to be an accurate reflection of the real world. Data should be valid and complete. Currently integrity issues have been handled external to the database in the application code. Codd (1985) states that integrity constraints specific to a particular RDBMS must be definable in SQL(e.g.) and stored in catalog.

Integrity 7. 5 A DBMS Enforced Integrity EMPLOYEE Table EMP# INTEGER NOT NULL Attempt to add an employee without an EMP# INSERT INTO EMPLOYEE ( EMP_NAME,AGE,SALARY) VALUES (‘Smith’,22,35000) This statement is rejected by the DBMS

Integrity 7. 6 An Application Based Integrity IF AGE > 16 OR AGE < 99 THEN O-K ELSE REJECT ‘Age Invalid’ This represents a segment of program code in an application program.

Integrity 7. 7 Integrity Enforcement Integrity enforcement is usually split between the DBMS and the application programs. Using application programs for integrity assertions has disadvantages. - Programming is more complex - Integrity constraints may be repeated - Change management is difficult - Constraints may contradict - Ad hoc operations may avoid the constraints

Integrity 7. 8 Codd’s CURED or CRUDE Classification of Integrities Type E - Entity Integrity Type R - Referential Integrity Type D - Domain Integrity :A user defined datatype Type C - Column Integrity:Linked to Domain integrity Type U - User Defined Integrity

Integrity 7. 9 Domain Integrity A domain is a conceptual pool of values from which one or more attributes draw their actual values. DOMAIN AGE RANGE ATTRIBUTE EMPLOYEE.AGE ATTRIBUTE DEPENDENT.AGE 0-60 Two values can only be compared if they come from the same domain.

Integrity Many things need to be considered when defining a domain A Domain Definition DOMAIN GENDER - Data Type: Character - Length: 6 bytes - Allowable Values: Male, Female, Null - Storage Format: Uppercase - Operations Allowed: - Inherited Operators: String, Unstring, = - Input Editing: Nil - Extra Functions: Is_ Male, Is_Female,What_Gender

Integrity To define the EMP table owned by SCOTT, you could issue the following statement: CREATE TABLE scott.emp (empnoNUMBER CONSTRAINT pk_emp PRIMARY KEY, enameVARCHAR2(10) CONSTRAINT nn_ename NOT NULL CONSTRAINT upper_ename CHECK (ename = UPPER(ename)), jobVARCHAR2(9), mgrNUMBER CONSTRAINT fk_mgr REFERENCES scott.emp(empno), hiredateDATE DEFAULT SYSDATE, salNUMBER(10,2) CONSTRAINT ck_sal CHECK (sal > 500), commNUMBER(9,0) DEFAULT NULL, deptnoNUMBER(2) CONSTRAINT nn_deptno NOT NULL CONSTRAINT fk_deptno REFERENCES scott.dept(deptno) ) ; This table contains 8 columns. For example, the EMPNO column is of datatype NUMBER and has an associated integrity constraint named PK_EMP. The HIRDEDATE column is of datatype DATE and has a default value of SYSDATE. Oracle Support for Integrity: An Example

Integrity An integrity constraint is a rule that restricts the values for one or more columns in a table. Column CONSTRAINT clauses can appear in either CREATE TABLE or ALTER TABLE commands. [CONSTRAINT constraint] [[NOT] NULL | UNIQUE | PRIMARY KEY ] [REFERENCES [user.] table[ (column) ] [ON DELETE CASCADE] [CHECK (condition) ] [EXCEPTIONS INTO [user.] table] [DISABLE ] Column_constraint syntax that appears in an ALTER TABLE statement can only define or remove a NOT NULL constraint. Oracle Integrity Constraints: Column

Integrity A table CONSTRAINT is identical to a column constraint except that it can reference multiple columns with a single constraint [CONSTRAINT constraint] {[NOT] NULL | [ {UNIQUE | PRIMARY KEY} (column[, column]) [FOREIGN KEY (column[, column]) [REFERENCES [user.] table[ (column[, column]) ] [ON DELETE CASCADE] [CHECK (condition) ] [EXCEPTIONS INTO [user.] table] [DISABLE ] Oracle Integrity Constraints: Table

Integrity The following statement alters the EMP table and defines and enables a NOT NULL constraint on the SAL column: ALTER TABLE emp MODIFY (sal NUMBER CONSTRAINT nn_sal NOT NULL) NN_SAL ensures that no employee in the table has a null salary. Example of an Alter Table

Integrity CREATE TABLE dept (deptno NUMBER(2), dname VARCHAR2(9) CONSTRAINT unq_dname UNIQUE, loc VARCHAR2(10) ) ; The constraint UNQ_DNAME identifies the DNAME column as a unique key. This constraint ensures that no two departments in the table have the same name. However, the constraint does allow departments without names. Alternatively, you can define and enable this constraint with the table_constraint syntax: CREATE TABLE dept (deptno NUMBER(2), dname VARCHAR2(9), loc VARCHAR2(10), CONSTRAINT unq_dname UNIQUE (dname)) ; Examples of Unique in Oracle

Integrity The UNIQUE constraint designates a column or combination of columns as a unique key. To satisfy a UNIQUE constraint, no two rows in the table can have the same value for the unique key. However, the unique key made up of a single column can contain nulls. A unique key column cannot be of datatype LONG or LONG RAW. You cannot designate the same column or combination of columns as both a unique key and a primary key or as both a unique key and a cluster key. However, you can designate the same column or combination of columns as both a unique key and a foreign key. You can define a unique key on a single column with column_constraint syntax. UNIQUE Constraints in Oracle

Integrity To define a composite unique key, you must use table_constraint syntax, rather than column_constraint syntax. To satisfy a constraint that designates a composite unique key, no two rows in the table can have the same combination of values in the key columns. Also, any row that contains nulls in all key columns automatically satisfies the constraint. However, two rows that contain nulls for one or more key columns and the same combination of values for the other key columns violate the constraint. The following statement defines and enables a composite unique key on the combination of the CITY and STATE columns of the CENSUS table: ALTER TABLE census ADD CONSTRAINT unq_city_state UNIQUE (city, state) EXCEPTIONS INTO bad_keys_in_ship_cont Defining Composite Unique Keys

Integrity A PRIMARY KEY constraint designates a column or combination of columns as the table's primary key. To satisfy a PRIMARY KEY constraint, both of the following conditions must be true: No primary key value can appear in more than one row in the table. No column that is part of the primary key can contain a null. A table can have only one primary key. A primary key column cannot be of datatype LONG or LONG RAW. You cannot designate the same column or combination of columns as both a primary key and a unique key or as both a primary key and a cluster key. However, you can designate the same column or combination of columns as both a primary key and a foreign key. PRIMARY KEY Constraints in Oracle

Integrity You can use the column_constraint syntax to define a primary key on a single column. The following statement creates the DEPT table and defines and enables a primary key on the DEPTNO column: CREATE TABLE dept (deptno NUMBER(2) CONSTRAINT pk_dept PRIMARY KEY, dname VARCHAR2(9), loc VARCHAR2(10) ) The PK_DEPT constraint identifies the DEPTNO column as the primary key of the DEPTNO table. This constraint ensures that no two departments in the table have the same department number and that no department number is NULL. Defining Primary Keys in Oracle

Integrity Alternatively, you can define and enable this constraint with table_constraint syntax: CREATE TABLE dept (deptno NUMBER(2), dname VARCHAR2(9), loc VARCHAR2(10), CONSTRAINT pk_dept PRIMARY KEY (deptno) ) Defining Composite Primary Keys A composite primary key is a primary key made up of a combination of columns. Because Oracle creates an index on the columns of a primary key, a composite primary key can contain a maximum of 16 columns. To define a composite primary key, you must use the table_constraint syntax, rather than the column_constraint syntax. Defining Primary Keys in Oracle

Integrity The following statement defines a composite primary key on the combination of the SHIP_NO and CONTAINER_NO columns of the SHIP_CONT table: ALTER TABLE ship_cont ADD PRIMARY KEY (ship_no, container_no) DISABLE This constraint identifies the combination of the SHIP_NO and CONTAINER_NO columns as the primary key of the SHIP_CONTAINER. The constraint ensures that no two rows in the table have the same values for both the SHIP_NO column and the CONTAINER_NO column. The CONSTRAINT clause also specifies the following properties of the constraint: Since the constraint definition does not include a constraint name, Oracle generates a name for the constraint. The DISABLE option causes Oracle to define the constraint but not enforce it. At a later time the ENABLE clause can be used to enable a single integrity constraint or all triggers associated with the table. Use of the Disable Option in Oracle

Integrity DEPT EMP Dno Dname Eno Ename Dno D5Research D6Advertising D7Newprojects E1 Smith D5 E2 Black D6 E3 Jones D6 E4 Brown is to be inserted. What check must be made to maintain integrity? An attempt to delete D5 Research occurs. What possible actions might take place to maintain integrity? DEPT EMP Referential Integrity

Integrity To Maintain Referential Integrity Event Delete corresponding Child records (Cascading Delete) OR Update Foreign Key of corresponding Child records (Cascading Update) Delete of Parent Update of Primary Key of Parent Insert of Child Action Parent Child Set the Foreign Key to null in the corresponding Child records (Delete or Update Nullifies) Do not allow the delete or update of the Parent record if any corresponding Child records exist(ie. the event fails to proceed) (Restricted Delete or Update) Check that null or a valid Primary Key from the Parent has been specified for the Foreign Key

Integrity The following statement creates the EMP table and defines and enables a foreign key on the DEPTNO column that references the primary key on the DEPTNO column of the DEPT table: CREATE TABLE emp (empno NUMBER(4), ename VARCHAR2(10), job VARCHAR2(9), mgr NUMBER(4), hiredate DATE, sal NUMBER(7,2), comm NUMBER(7,2), deptno NUMBER(2) CONSTRAINT fk_deptno REFERENCES dept(deptno) ) Oracle Referential Integrity Constraints

Integrity ON DELETE CASCADE allows deletion of referenced key values in the parent table that have dependent rows in the child table and causes Oracle to automatically delete dependent rows from the child table to maintain referential integrity. If you omit this option, Oracle forbids deletions of referenced key values in the parent table that have dependent rows in the child table. You can define multiple foreign keys in a table. Also, a single column can be part of more than one foreign key. Keywords in Oracle Referential Integrities

Integrity CREATE TABLE emp (empno NUMBER(4), ename VARCHAR2(10), job VARCHAR2(9), mgr NUMBER(4), hiredate DATE, sal NUMBER(7,2), comm NUMBER(7,2), deptno NUMBER(2), CONSTRAINT fk_deptno FOREIGN KEY (deptno) REFERENCES dept(deptno) ) Note that the foreign key definitions in both of the above statements omit the ON DELETE CASCADE option, causing Oracle to forbid the deletion of a department if any employee works in that department. If you use the ON DELETE CASCADE option, Oracle permits deletions of referenced key values in the parent table and automatically deletes dependent rows in the child table to maintain referential integrity. Example With Table_constraint Syntax

Integrity This example creates the EMP table, defines and enables the referential integrity constraint FK_DEPTNO, and uses the ON DELETE CASCADE option: CREATE TABLE emp (empno NUMBER(4), ename VARCHAR2(10), job VARCHAR2(9), mgr NUMBER(4), hiredate DATE, sal NUMBER(7,2), comm NUMBER(7,2), deptno NUMBER(2) CONSTRAINT fk_deptno REFERENCES dept(deptno) ON DELETE CASCADE ) The ON DELETE CASCADE Option

Integrity ALTER TABLE phone_calls ADD CONSTRAINT fk_areaco_phoneno FOREIGN KEY (areaco, phoneno) REFERENCES customers(areaco, phoneno) EXCEPTIONS INTO wrong_numbers The constraint FK_AREACO_PHONENO ensures that all the calls in the PHONE_CALLS table are made from phone numbers that are listed in the CUSTOMERS table. Before you define and enable this constraint, you must define and enable a constraint that designates the combination of the AREACO and PHONENO columns of the CUSTOMERS table as a primary or unique key. The EXCEPTIONS option causes Oracle to write information into WRONG_NUMBERS table about any rows in the PHONE_CALLS table that violate the constraint. A Foreign Key Constraint on two Columns

Integrity CREATE TABLE dept (deptno NUMBER CONSTRAINT check_deptno CHECK (deptno BETWEEN 10 AND 99) DISABLE, dname VARCHAR2(9) CONSTRAINT check_dname CHECK (dname = UPPER(dname)) DISABLE, loc VARCHAR2(10) CONSTRAINT check_loc CHECK (loc IN ('DALLAS','BOSTON', 'NEW YORK','CHICAGO')) DISABLE) Unlike other types of constraints, a CHECK constraint defined with column_constraint syntax can impose rules on any column in the table, rather than only on the column in which it is defined. Because each CONSTRAINT clause contains the DISABLE option, Oracle only defines the constraints and does not enforce them. Example of a CHECK Constraint on a Column

Integrity The following statement creates the EMP table and uses a table constraint clause to define and enable a CHECK constraint: CREATE TABLE emp (empno NUMBER(4), ename VARCHAR2(10), job VARCHAR2(9), mgr NUMBER(4), hiredate DATE, sal NUMBER(7,2), comm NUMBER(7,2), deptno NUMBER(2), CHECK (sal + comm <= 5000) ) Example of a CHECK Constraint on a Table

Integrity CREATE TABLE order_detail (CONSTRAINT pk_od PRIMARY KEY (order_id, part_no), order_id NUMBER CONSTRAINT fk_oid REFERENCES scott.order (order_id), part_no NUMBER CONSTRAINT fk_pno REFERENCES scott.part (part_no), quantity NUMBER CONSTRAINT nn_qty NOT NULL CONSTRAINT check_qty_low CHECK (quantity > 0), cost NUMBER CONSTRAINT check_cost CHECK (cost > 0) ) More Than One CHECK Constraint on a Table

Integrity This example creates a BEFORE statement trigger named EMP_PERMIT_CHANGES in the schema SCOTT. This trigger ensures that changes to employee records are only made during business hours on working days: CREATE TRIGGER scott.emp_permit_changes BEFORE DELETE OR INSERT OR UPDATE ON scott.emp DECLARE dummy INTEGER; BEGIN /* If today is a Saturday or Sunday, then return an error.*/ IF (TO_CHAR(SYSDATE, 'DY') = 'SAT' OR TO_CHAR(SYSDATE, 'DY') = 'SUN') THEN raise_application_error( , 'May not change employee table during the weekend'); END IF; Example of a Trigger

Integrity /* Compare today's date with the dates of all company holidays. If today is a company holiday, then return an error. */ SELECT COUNT(*) INTO dummy FROM company_holidays WHERE day = TRUNC(SYSDATE); IF dummy > 0 THEN raise_application_error( , 'May not change employee table during a holiday'); END IF; /* If the current time is before 8:00AM or after 6:00PM, then return an error. */ IF (TO_CHAR(SYSDATE, 'HH24') < 8 OR TO_CHAR(SYSDATE, 'HH24') >= 18) THEN raise_application_error( , 'May only change employee table during working hours'); END IF; END;

Integrity This example creates a BEFORE row trigger named SALARY_CHECK in the schema SCOTT. Whenever a new employee is added to the employee table or an existing employee's salary or job is changed, this trigger guarantees that the employee's salary falls within the established salary range for the employee's job: CREATE TRIGGER scott.salary_check BEFORE INSERT OR UPDATE OF sal, job ON scott.emp FOR EACH ROW WHEN (new.job <> 'PRESIDENT') DECLARE minsal NUMBER; maxsal NUMBER; A Second Example of a Trigger

Integrity BEGIN /* Get the minimum and maximum salaries for the employee's job from the SAL_GUIDE table. */ SELECT minsal, maxsal INTO minsal, maxsal FROM sal_guide WHERE job = :new.job; /* If the employee's salary is below the minimum or */ /* above the maximum for the job, then generate an */ /* error. */ IF (:new.sal maxsal) THEN raise_application_error( , 'Salary ' || :new.sal || ' out of range for job ' || :new.job || ' for employee ' || :new.ename ); END IF; END;

Integrity OR REPLACE recreates the trigger if it already exists. You can use this option to change the definition of an existing trigger without first dropping it. BEFORE / AFTER indicates that Oracle fires the trigger before or after executing the triggering statement. For row triggers, this is a separate firing before or after each affected row is changed. DELETE indicates that Oracle fires the trigger whenever a DELETE statement removes a row from the table. INSERT indicates that Oracle fires the trigger whenever an INSERT statement adds a row to table. UPDATE OF indicates that Oracle fires the trigger whenever an UPDATE statement changes a value in one of the columns specified in the OF clause. If you omit the OF clause, Oracle fires the trigger whenever an UPDATE statement changes a value in any column of the table. Oracle CREATE TRIGGER Keywords

Integrity ON specifies the schema and name of the table on which the trigger is to be created. If you omit schema, Oracle assumes the table is in your own schema. You cannot create a trigger on a table in the schema SYS. REFERENCING specifies correlation names. You can use correlation names in the PL/SQL block and WHEN clause of a row trigger to refer specifically to old and new values of the current row. The default correlation names are OLD and NEW. If your row trigger is associated with a table named OLD or NEW, you can use this clause to specify different correlation names. FOR EACH ROW designates the trigger to be a row trigger. Oracle fires a row trigger once for each row that is affected by the trigger statement and meets the optional trigger constraint (defined in WHEN) WHEN clause. specifies the trigger restriction. The trigger restriction contains a SQL condition that must be satisfied for Oracle to fire the trigger. This condition must contain correlation names and cannot contain a query. You can only specify a trigger restriction for a row trigger. Oracle evaluates this condition for each row affected by the triggering statement. Oracle CREATE TRIGGER Keywords