Wednesday, December 16, 2009

CHECK Constraint

CHECK Constraint :

Defines a condition that each row must satisfy
  • The following expressions are not allowed :
  • References to CURR_VAL, NEXT_VAL and CTID pseudocolumns
  • Queries that refer to other values in other rows
  • ..., salary numeric(2)CONSTRAINT emp_salary_minCHECK (salary > 0),...
CREATE TABLE : Example

Tuesday, December 15, 2009

FOREIGN KEY Constraint

  • Defined at either the table level or the column level
  • CREATE TABLE emp(employee_id numeric(6), last_name varchar(25) NOT NULL, email varchar(25), salary numeric(8,2), commission_pct numeric(2,2), hire_date DATE NOT NULL, ... department_id numeric(4), CONSTRAINT emp_dept_fk FOREIGN KEY (department_id) REFERENCES dept(deptno), CONSTRAINT emp_email_uk UNIQUE(email));
FOREIGN KEY Constraint - Keywords :
  • FOREIGN KEY : Defines the column in the child table at the table-constraint level
  • REFERENCES : Identifies the table and column in the parent table
  • ON DELETE CASCADE : Deletes the dependent rows in the child table when a row in the parent table is deleted
  • ON DELETE SET NULL : Converts dependent foreign key values to null

Followers