Oracle SQL - Add foreign key in table definition

Description

Add foreign key in table definition

create table offerings
( course     VARCHAR2(6)  constraint O_COURSE_NN not null
                          constraint O_COURSE_FK references courses
, begindate  DATE         constraint O_BEGIN_NN  not null
, trainer    NUMBER(4)    constraint O_TRAIN_FK  references emp
, location   VARCHAR2(8)
,                         constraint O_PK        primary key
                                                 (course,begindate)
) ;
create table registrations
( attendee    NUMBER(4)   constraint R_ATT_NN    not null
                          constraint R_ATT_FK    references emp
, course      VARCHAR2(6) constraint R_COURSE_NN not null
, begindate   DATE        constraint R_BEGIN_NN  not null
, evaluation  NUMBER(1)   constraint R_EVAL_CHK  check (evaluation in (1,2,3,4,5))
,                         constraint  R_PK       primary key
                                                 (attendee,course,begindate)
,                         constraint  R_OFF_FK   foreign key (course,begindate)
                                                 references offerings
) ;

Related Topic