欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Oracle外键约束子表、父表

程序员文章站 2022-05-15 19:37:44
...

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