当前位置:Gxlcms > mysql > Oracle外键约束子表、父表

Oracle外键约束子表、父表

时间:2021-07-01 10:21:17 帮助过:24人阅读

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

人气教程排行