Oracle SQL in 10 Minutes - Asim Abbasi
CH1: SQL Basics | CH2: SQL Operators | CH3: SQL Built-in Functions | CH4: SQL Joins | CH5: UPDATE, INSERT & DELETE Statements | CH6: CREATE, ALTER & DROP Statements | CH7: Constraints | CH8: Linking Tables vs Joining Tables | CH9: SQL Statements for Other Database Objects | CH10: SQL Statements for Database Security
Chapter 7: Constraints
• Keeping in focus PRIMARY KEY constraint column value(s) of parent
table, if someone tries to delete a record from the parent table and
there are corresponding value(s) in one or more child table(s) FOREIGN
KEY constraint column, this task with result in Referential Integrity
constraint violation error. But we can override this clause if we add ON
DELETE CASCADE clause as shown in the example below.
CREATE TABLE emp_test
(empno NUMBER(4) CONSTRAINT pk_dept_test PRIMARY KEY,
ename VARCHAR2(10),
job VARCHAR2(10),
deptno NUMBER(3),
CONSTRAINT fk_emp_test FOREIGN KEY (deptno) REFERENCES dept_test(deptno)
ON DELETE CASCADE
);
Because of the cascade delete, when a record in the dept_test table is
deleted, all records in the emp_test table will also be deleted that
have the same deptno value.
Chapter 7: Constraints
CH1: SQL Basics | CH2:
SQL Operators |
CH3: SQL Built-in Functions | CH4:
SQL Joins | CH5:
UPDATE, INSERT & DELETE Statements |
CH6: CREATE, ALTER & DROP Statements | CH7:
Constraints | CH8:
Linking Tables vs Joining Tables | CH9:
SQL
Statements for Other Database Objects | CH10:
SQL Statements for
Database Security Share with others: