Oracle composite primary key / foreign key question

后端 未结 4 1694
余生分开走
余生分开走 2021-02-13 22:37

I have a composite primary key in 1 table in oracle. I want to create a foreign key for one table entry in my second table that references the composite primary key in the firs

4条回答
  •  执念已碎
    2021-02-13 23:26

    CREATE TABLE groupspersonx( 
      personid number, groupid number, 
    CONSTRAINT pk_persongroupid PRIMARY KEY(personid, groupid));
    
    CREATE TABLE restrictedgroups ( 
      pid number, 
      groupid number,
      name varchar2(50), 
      dateadded date, 
      since date, 
      notes varchar2(1024), 
      CONSTRAINT pk_groupid PRIMARY KEY(groupid), 
      CONSTRAINT fk_persongroup FOREIGN KEY(pid,groupid) REFERENCES groupspersonx(personid, groupid));
    

    * number of references columns is equals with foreign key columns

提交回复
热议问题