sql - Error :ORA-02270 -
the error got .
foreign key (bid) references allocation (bid), *
error @ line 8: ora-02270: no matching unique or primary key column-list
not sure how fix it. allocation , worksession week entities. helps appreciated.
create table book( bid number(4), title varchar2(30) constraint nn_title not null, sellingprice number(6,2) constraint chk_selling_price check(sellingprice>0), primary key (bid) ); create table author( authorid number(4), sname varchar2(30), fname varchar(30), primary key (authorid), constraint uc_author_name unique(sname,fname) ); create table allocation( bid number(4), authorid number(4), payrate number(6,2) constraint chk_pay_rate check(payrate>1 , payrate<79.99), primary key (bid,authorid), foreign key (bid) references book (bid), foreign key (authorid) references author (authorid) ); create table worksession( bid number(4), authorid number(4), workyear number(4) constraint chk_workyear check(workyear<2013 , workyear>2011), workweek number(2) constraint chk_workweek check(workweek>1 , workweek<52), workhours number(4,2) constraint chk_workhours check(workhours>0.5 , workhours<99.99), primary key (bid,authorid,workyear,workweek), ***foreign key (bid) references allocation (bid), foreign key (authorid) references allocation (authorid) );
your fk must point an existing primary key (pk) or unique key(uk);
use create statement last table:
create table worksession( bid number(4), authorid number(4), workyear number(4) constraint chk_workyear check(workyear<2013 , workyear>2011), workweek number(2) constraint chk_workweek check(workweek>1 , workweek<52), workhours number(4,2) constraint chk_workhours check(workhours>0.5 , workhours<99.99), primary key (bid,authorid,workyear,workweek), ***foreign key (bid) references allocation (bid), foreign key (bid, authorid) references allocation (bid, authorid) );
Comments
Post a Comment