萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> oracle教程 >> Oracle外鍵約束子表、父表

Oracle外鍵約束子表、父表

   CREATE TABLE employees(

  employee_id NUMBER(6),

  last_name VARCHAR2(25) NOT NULL,

  email VARCHAR2(25),

  salary NUMBER(8,2),

  commission_pct NUMBER(2,2),

  hire_date DATE NOT NULL,

  ...

  department_id NUMBER(4),

  CONSTRAINT emp_dept_fk FOREIGN KEY (department_id)

  REFERENCES departments(department_id),

  CONSTRAINT emp_email_uk UNIQUE(email));

  FOREIGN KEY:在表級指定子表中的列

  REFERENCES:標識在父表中的列

  ON DELETE CASCADE:當父表中的列被刪除時,子表中相對應的列也被刪除

  ON DELETE SET NULL:子表中相應的列置空

copyright © 萬盛學電腦網 all rights reserved