Home  >  Article  >  Database  >  Oracle外键约束子表、父表

Oracle外键约束子表、父表

WBOY
WBOYOriginal
2016-06-07 16:22:431121browse

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 (d

   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:子表中相应的列置空

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn