Oracle

FOREIGN KEY Constraint

Figo Kim 2006. 11. 23. 22:00
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
1. A foreign key value must match an existing value in the parent table or be NULL
2. Foreign keys are based on data values and are purely logical, rather than physical, pointer.

CREATE TABLE employees
  ( employee_id    NUMBER(6)
  , first_name     VARCHAR2(20)
  , last_name      VARCHAR2(25) NOT NULL
  , email          VARCHAR2(25)
  , phone_number   VARCHAR2(20)
  , hire_date      DATE

.....
  ,department_id  NUMBER(4)
  ,CONSTRAINT emp_dept_fk FOREIGH KEY (department_id)
       REFERENCES departments(department_id),

  ,CONSTRAINT emp_email_uk UNIQUE(email));

CREATE TABLE employees
(
...
department_id NUMBER(4) CONSTRAINT emp_deptid_fk
REFERENCE departments(department_id),
...
)

** keyword FOREIGN KEY doesn't appear.



  • FOREIGN KEY : To define the column in the child table at the table-constraint level.
  • ON DELETE CASCADE : Deletes the depandent rows in the child table when a row in the parent is deleted.
  • ON DELETE SET NULL : Converts dependent foreign key values to null when the parent value is removed.
  • Without the ON DELETE CASCADE or the ON DELETE SET NULL options, the row in the parent table cannot be deleted if it is referenced in the child table.

** Without the ON DELETE CASCADE or the ON DELETE SET NULL options, the row in the parent table cannot be deleted if it is referenced in the child table.

'Oracle' 카테고리의 다른 글

CHECK Constraint  (0) 2006.11.23
FOREIGN KEY Constraint  (0) 2006.11.23
PRIMARY KEY Constraint  (0) 2006.11.23
PRIMARY KEY Constraint  (0) 2006.11.23
Unique Constraint  (0) 2006.11.23