Oracle SQL missing smth - sql

Trying to build these tables and there's always an error or missing something, can someone help me?
Where's max_mice i'm checking if it's inbetween those values and doesn't work why?
Don't know what's wrong, already searched everywhere, don't know why they won't be created...
updated: now i got problems on table incidents...
update: the error was that i had: CONSTRAINT fun_maxmi_ch CHECK (200 > max_mice >= min_mice) instead of the code below.
CREATE TABLE Functions (
function VARCHAR(10) CONSTRAINT fun_fu_pk PRIMARY KEY,
min_mice NUMBER(3) CONSTRAINT fun_minmi_ch CHECK (min_mice > 5),
max_mice NUMBER(3),
CONSTRAINT fun_maxmi_ch CHECK (max_mice >= min_mice and max_mice < 200)
);
BUT still have a problem creating table Incidents don't know what's the problem!!!
CREATE TABLE Incidents (
nickname VARCHAR2(15),
enemy_name VARCHAR2(15),
incident_date DATE CONSTRAINT inc_indate_nn NOT NULL,
incident_desc VARCHAR2(50),
CONSTRAINT inc_con_pk PRIMARY KEY (nickname, enemy_name),
CONSTRAINT inc_nic_fk FOREIGN KEY (nickname) REFERENCES Cats(nickname),
CONSTRAINT inc_enname_fk FOREIGN KEY (enemy_name) REFERENCES Enemies(enemy_name),
);
Here's the full code:
CREATE TABLE Enemies (
enemy_name VARCHAR2(15),
hostility_degree NUMBER(2) CONSTRAINT hos_degree_ch CHECK (hostility_degree BETWEEN 1 AND 10),
species VARCHAR2(15),
bride VARCHAR2(20),
CONSTRAINT ene_name_pk PRIMARY KEY(enemy_name)
);
CREATE TABLE Functions (
function VARCHAR(10) CONSTRAINT fun_fu_pk PRIMARY KEY,
min_mice NUMBER(3) CONSTRAINT fun_minmi_ch CHECK (min_mice > 5),
max_mice NUMBER(3),
CONSTRAINT fun_maxmi_ch CHECK (max_mice >= min_mice and max_mice < 200)
);
CREATE TABLE Bands (
Band_no NUMBER(2) CONSTRAINT ban_no_pk PRIMARY KEY,
name VARCHAR2(20) CONSTRAINT ban_name_nn NOT NULL,
site VARCHAR2(15) CONSTRAINT ban_site_un UNIQUE,
band_chief VARCHAR(15) CONSTRAINT ban_chief_un UNIQUE
);
CREATE TABLE Cats (
name VARCHAR2(15) CONSTRAINT cat_name_nn NOT NULL,
gender VARCHAR2(1) CONSTRAINT cat_gen_ch CHECK (gender IN('M', 'W')),
nickname VARCHAR2(15) CONSTRAINT cat_pk PRIMARY KEY,
function VARCHAR2(10),
chief VARCHAR2(15),
in_herd_since DATE DEFAULT SYSDATE CONSTRAINT cat_inherd_nn NOT NULL,
mice_ration NUMBER(3),
mice_extra NUMBER(3),
band_no NUMBER(2),
CONSTRAINT cat_banno_fk FOREIGN KEY (band_no) REFERENCES Bands(band_no),
CONSTRAINT cat_chief_fk FOREIGN KEY (chief) REFERENCES Cats(nickname),
CONSTRAINT cat_fun_fk FOREIGN KEY (function) REFERENCES Functions(function)
);
ALTER TABLE Bands
ADD CONSTRAINT ban_chief_fk FOREIGN KEY (band_chief) REFERENCES Cats(nickname);
CREATE TABLE Incidents (
nickname VARCHAR2(15),
enemy_name VARCHAR2(15),
incident_date DATE CONSTRAINT inc_indate_nn NOT NULL,
incident_desc VARCHAR2(50),
CONSTRAINT inc_con_pk PRIMARY KEY (nickname, enemy_name),
CONSTRAINT inc_nic_fk FOREIGN KEY (nickname) REFERENCES Cats(nickname),
CONSTRAINT inc_enname_fk FOREIGN KEY (enemy_name) REFERENCES Enemies(enemy_name),
);

here's max_mice i'm checking if it's in between those values and doesn't work why?
When it comes to the first table in your code, Functions, the problem is with the declaration of the last check constraint:
max_mice NUMBER(3) CONSTRAINT fu_maxmi_ch CHECK (200 > max_mice >= min_mouse)
Issues:
the double inequality condition is not supported
a multi-column check constraint need to be declared at table level rather than at column level
This works:
CREATE TABLE Functions (
function VARCHAR(10) CONSTRAINT fu_fu_pk PRIMARY KEY,
min_mice NUMBER(3) CONSTRAINT fu_minmi_ch CHECK (min_mice > 5),
max_mice NUMBER(3),
CONSTRAINT fu_maxmi_ch CHECK (max_mice >= min_mice and max_mice < 200)
);
Note: I would not recommend naming a column function, since it obviously conflicts with a SQL keyword.

Related

Is it possible to create to tables that reference each other without using ALTER? [duplicate]

This question already has an answer here:
Is there any other way to create constraints during SQL table creation?
(1 answer)
Closed 2 years ago.
I am new to databases in general and would like to have an answer to a problem that I am facing.
I would like to know if there is away two create two tables that reference each other without creating one and Altering it later and adding the reference.
CREATE TABLE Cats(
name VARCHAR2(15) CONSTRAINT cat_name_nn NOT NULL,
gender VARCHAR2(1) CONSTRAINT cat_gd CHECK(gender IN('W', 'M')),
nickname VARCHAR2(15) CONSTRAINT cat_pk PRIMARY KEY,
function VARCHAR2(10) CONSTRAINT cat_fn REFERENCES Functions(function),
chief VARCHAR2(15) CONSTRAINT cat_chf REFERENCES Cats(nickname),
in_herd_sinnce DATE DEFAULT SYSDATE,
mice_ration NUMBER(3),
mice_extra NUMBER(3),
band_no NUMBER(2) CONSTRAINT cat_bno REFERENCES Bands(band_no))
CREATE TABLE Bands(
band_no NUMBER(2) CONSTRAINT bd_pk PRIMARY KEY,
name VARCHAR2(20) CONSTRAINT bd_name_nn NOT NULL,
site VARCHAR2(15) CONSTRAINT bd_site_un UNIQUE,
band_chief VARCHAR2(15) CONSTRAINT bd_chf_un UNIQUE
CONSTRAINT bd_chf_nm REFERENCES Cats(nickname)
);
As far as I remember I can not do it; I am right?
No, it cannot be done. Whichever table you CREATE first cannot have a foreign key to the other table as that other table does not exist yet; instead you need to create the tables and then use ALTER TABLE ADD CONSTRAINT to create the constraint from the first table to the second.
For example:
CREATE TABLE Functions ( function VARCHAR2(10) CONSTRAINT fn_fn PRIMARY KEY );
CREATE TABLE Cats(
name VARCHAR2(15) CONSTRAINT cat_name_nn NOT NULL,
gender VARCHAR2(1) CONSTRAINT cat_gd CHECK(gender IN('W', 'M')),
nickname VARCHAR2(15) CONSTRAINT cat_pk PRIMARY KEY,
function VARCHAR2(10) CONSTRAINT cat_fn REFERENCES Functions(function),
chief VARCHAR2(15) CONSTRAINT cat_chf REFERENCES Cats(nickname),
in_herd_sinnce DATE DEFAULT SYSDATE,
mice_ration NUMBER(3),
mice_extra NUMBER(3),
band_no NUMBER(2)
);
CREATE TABLE Bands(
band_no NUMBER(2) CONSTRAINT bd_pk PRIMARY KEY,
name VARCHAR2(20) CONSTRAINT bd_name_nn NOT NULL,
site VARCHAR2(15) CONSTRAINT bd_site_un UNIQUE,
band_chief VARCHAR2(15) CONSTRAINT bd_chf_un UNIQUE
CONSTRAINT bd_chf_nm REFERENCES Cats(nickname)
);
ALTER TABLE CATS ADD CONSTRAINT cat_bno FOREIGN KEY ( band_no )
REFERENCES Bands(band_no);
db<>fiddle here

Oracle (ORA-02270) : Have tried following other answers but can not figure it out

Complete beginner here. I have been trying to mess around with this code and I stripped it back to this:
create table Customer
(
Customer_Num varchar2(7) not null,
Surname varchar2(50) not null,
Other_Names varchar2(100) not null,
Email varchar2(320) not null,
Mobile_Phone varchar2(20) not null,
constraint Customer_PK primary key (Customer_Num)
);
create table Store
(
Store_ID varchar2(5) not null,
Region varchar2(50) not null,
constraint Store_PK primary key (Store_ID)
);
create table Sale
(
Store_ID varchar2(5) not null,
Recorded_On timestamp not null,
Customer_Num varchar2(7) not null,
Comments varchar2(4000),
constraint Product_PK primary key (Store_ID, Recorded_On),
constraint Sale_Store_FK foreign key (Store_ID) references Store(Store_ID),
constraint Sale_Customer_FK foreign key (Customer_Num) references Customer(Customer_Num)
);
create table Product
(
Store_ID varchar2(5) not null,
Recorded_On timestamp not null,
Product_Name varchar2(50),
Value varchar2(50),
constraint Product_PK primary key(Value),
constraint Product_FK foreign key(Store_ID) references Store(Store_ID),
constraint Product_FK foreign key(Recorded_On) references Sale(Recorded_On)
);
Error starting at line : 67 in command -
create table Product
(
Store_ID varchar2(5) not null,
Recorded_On timestamp not null,
Product_Name varchar2(50),
Value varchar2(50),
constraint Product_PK primary key(Value),
constraint Product_FK foreign key(Store_ID) references Store,
constraint Product_FK foreign key(Recorded_On) references Sale(Recorded_On)
)
Error report -
SQL Error: ORA-02270: no matching unique or primary key for this column-list
02270. 00000 - "no matching unique or primary key for this column-list"
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view
Thanks in advance!
UPDATE *
I have changed code as follows
create table Customer
(
Customer_Num varchar2(7) not null,
Surname varchar2(50) not null,
Other_Names varchar2(100) not null,
Email varchar2(320) not null,
Mobile_Phone varchar2(20) not null,
constraint Customer_PK primary key (Customer_Num)
);
create table Store
(
Store_ID varchar2(5) not null,
Region varchar2(50) not null,
constraint Store_PK primary key (Store_ID)
);
create table Sale
(
Store_ID varchar2(5) not null,
Recorded_On timestamp not null UNIQUE,
Customer_Num varchar2(7) not null,
Comments varchar2(4000),
constraint Sale_PK primary key (Store_ID, Recorded_On),
constraint Sale_Store_FK foreign key (Store_ID) references Store(Store_ID),
constraint Sale_Customer_FK foreign key (Customer_Num) references Customer
);
create table Product
(
Store_ID varchar2(5) not null,
Recorded_On timestamp not null,
Product_Name varchar2(50),
Value varchar2(50),
constraint Product_PK primary key(Store_ID, Recorded_On),
constraint Product_Store_FK foreign key(Store_ID) references Store,
constraint Product_recorded_FK foreign key(Recorded_On) references Sale(Recorded_On)
);
Now I run into this error when inserting statement:
INSERT INTO Product (Store_ID, Recorded_On, Product_Name, Value) VALUES ('AB1', to_date('10/05/2016 13:11', 'DD/MM/YYYY HH24:MI'), 'Test', 2.0);
Error starting at line : 80 in command -
INSERT INTO Product (Store_ID, Recorded_On, Product_Name, Value) VALUES ('AB1', to_date('10/05/2016 13:11', 'DD/MM/YYYY HH24:MI'), 'Test', 2.0)
Error report -
SQL Error: ORA-02291: integrity constraint (Hemi89.PRODUCT_RECORDED_FK) violated - parent key not found
02291. 00000 - "integrity constraint (%s.%s) violated - parent key not found"
*Cause: A foreign key value has no matching primary key value.
*Action: Delete the foreign key or add a matching primary key.
I am little confused here as I believe I have set parent key in constraint Sale_PK primary key (Store_ID, Recorded_On) in the Sales Table.
The foreign key you're trying to create on Recorded_On column in product table must refer to a primary key or an unique key. Recorded_On column in your Sale table must be changed to unique or don't create any constraints on it.
After you resolve this error, the next problem you'll run into is constraints not having unique names.
ORA-02264: name already used by an existing constraint
Constraint Name Product_PK & Product_FK gets repeated twice.

Why this SQL code showing error of "missing right parenthesis"?

CREATE TABLE PoolActivity_T
(PoolID NUMBER(11,0) NOT NULL,
ServiceDate DATE DEFAULT SYSDATE NOT NULL,
ActivityID NUMBER(11,0) NOT NULL,
CONSTRAINT PoolActivity_PK PRIMARY KEY (PoolID,ServiceDate,ActivityID)
CONSTRAINT PoolActivity_FK FOREIGN KEY (PoolID)
REFERENCES PoolVisit_T(PoolID),
CONSTRAINT PoolActivity_FK FOREIGN KEY (ActivityID)
REFERENCES Activity_T (ActivityID)
);
Here is my code and I can not figure out why comes the error.
CREATE TABLE Customer_T
(CustomerID NUMBER(11,0) NOT NULL,
CustomerFname VARCHAR2(25),
CustomerMname VARCHAR2(25),
CustomerLname VARCHAR2(25),
CustomerAddress1 VARCHAR2(50),
CustomerAddress2 VARCHAR2(50),
CustomerCity VARCHAR2(25),
CustomerState CHAR(2),
CustomerZipCode NUMBER(5,0),
CustomerPhoneNumber NUMBER(11,0),
CONSTRAINT Customer_PK PRIMARY KEY (CustomerID)
);
CREATE TABLE Pool_T
(PoolID NUMBER(11,0) NOT NULL,
PoolAddress1 VARCHAR2(25),
PoolAddress2 VARCHAR2(25),
PoolCity VARCHAR2(25),
PoolState VARCHAR2(25),
PoolZipCode NUMBER(5,0),
TypeSurface VARCHAR2(9),
Gallon INTEGER,
Filters VARCHAR2(25),
VisitPerMonth INTEGER,
Dates DATE DEFAULT SYSDATE,
Fee NUMBER(11,0),
CONSTRAINT Pool_PK PRIMARY KEY (PoolID)
);
CREATE TABLE PoolVisit_T
(PoolID NUMBER(11,0) NOT NULL,
ServiceDate DATE DEFAULT SYSDATE NOT NULL,
LengthStay INTEGER,
CONSTRAINT Poolvisit_PK PRIMARY KEY (PoolID,ServiceDate)
CONSTRAINT PoolVisit_FK FOREIGN KEY (PoolID)
REFERENCES Pool_T (PoolID)
);
CREATE TABLE PoolActivity_T
(PoolID NUMBER(11,0) NOT NULL,
ServiceDate DATE DEFAULT SYSDATE NOT NULL,
ActivityID NUMBER(11,0) NOT NULL,
CONSTRAINT PoolActivity_PK PRIMARY KEY (PoolID,ServiceDate,ActivityID)
CONSTRAINT PoolActivity_FK FOREIGN KEY (PoolID)
REFERENCES PoolVisit_T(PoolID),
CONSTRAINT PoolActivity_FK FOREIGN KEY (ActivityID)
REFERENCES Activity_T (ActivityID)
);
CREATE TABLE PoolChemical_T
(PoolID NUMBER(11,0) NOT NULL,
ServiceDate DATE DEFAULT SYSDATE NOT NULL,
ChemicalName VARCHAR2(25) NOT NULL,
Quantity INTEGER,
Cost NUMBER(11,2),
CONSTRAINT PoolChemical_PK PRIMARY KEY (PoolID,ServiceDate,ChemicalName)
CONSTRAINT PoolChemical_FK FOREIGN KEY (PoolID)
REFERENCES PoolVisit_T(PoolID)
CONSTRAINT PoolChemical_FK FOREIGN KEY (ChemicalName)
REFERENCES Chemical_T(ChemicalName)
);
CREATE TABLE Activity_T
(ActivityID NUMBER(11,0) NOT NULL,
ActivityDesc VARCHAR2(500),
CONSTRAINT Activity_PK PRIMARY KEY (ActivityID));
CREATE TABLE Chemical_T
(ChemicalName VARCHAR2(25) NOT NULL,
CONSTRAINT Chemical_PK PRIMARY KEY (ChemicalName));
The error isn't just in the table you highlighted, it's also in the one before, PoolVisit_T. In both, you're just missing a comma after the primary key constraint:
CREATE TABLE PoolVisit_T
(PoolID NUMBER(11,0) NOT NULL,
ServiceDate DATE DEFAULT SYSDATE NOT NULL,
LengthStay INTEGER,
CONSTRAINT Poolvisit_PK PRIMARY KEY (PoolID,ServiceDate), -- was missing comma
CONSTRAINT PoolVisit_FK FOREIGN KEY (PoolID)
REFERENCES Pool_T (PoolID)
);
CREATE TABLE PoolActivity_T
(PoolID NUMBER(11,0) NOT NULL,
ServiceDate DATE DEFAULT SYSDATE NOT NULL,
ActivityID NUMBER(11,0) NOT NULL,
CONSTRAINT PoolActivity_PK PRIMARY KEY (PoolID,ServiceDate,ActivityID), -- was missing
CONSTRAINT PoolActivity_FK FOREIGN KEY (PoolID)
REFERENCES PoolVisit_T(PoolID),
CONSTRAINT PoolActivity_FK FOREIGN KEY (ActivityID)
REFERENCES Activity_T (ActivityID)
);
And you're missing two in the one after that:
CREATE TABLE PoolChemical_T
(PoolID NUMBER(11,0) NOT NULL,
ServiceDate DATE DEFAULT SYSDATE NOT NULL,
ChemicalName VARCHAR2(25) NOT NULL,
Quantity INTEGER,
Cost NUMBER(11,2),
CONSTRAINT PoolChemical_PK PRIMARY KEY (PoolID,ServiceDate,ChemicalName), -- was missing
CONSTRAINT PoolChemical_FK FOREIGN KEY (PoolID)
REFERENCES PoolVisit_T(PoolID), -- was missing
CONSTRAINT PoolChemical_FK FOREIGN KEY (ChemicalName)
REFERENCES Chemical_T(ChemicalName)
);
If you use an IDE like SQL Developer it will highlight syntax problems like this as you go.
But you still have issues; your PoolActivity_T foreign key:
CONSTRAINT PoolActivity_FK FOREIGN KEY (PoolID)
REFERENCES PoolVisit_T(PoolID),
is referring only to the PoolID, but the primary key on PoolVisit_T and the primary key has two columns, so that needs to be:
CONSTRAINT PoolActivity_FK FOREIGN KEY (PoolID,ServiceDate)
REFERENCES PoolVisit_T(PoolID,ServiceDate),
And you've used the same FK name for two constraints, so the next bit is:
CONSTRAINT PoolActivity_FK2 FOREIGN KEY (ActivityID)
REFERENCES Activity_T (ActivityID)
(but pick more descriptive FK names, perhaps), and you have to create the Activity_T table before this one.
And similar issues with PoolChemical_T:
CONSTRAINT PoolChemical_PK PRIMARY KEY (PoolID,ServiceDate,ChemicalName),
CONSTRAINT PoolChemical_FK FOREIGN KEY (PoolID,ServiceDate)
REFERENCES PoolVisit_T(PoolID,ServiceDate),
CONSTRAINT PoolChemical_FK2 FOREIGN KEY (ChemicalName)
REFERENCES Chemical_T(ChemicalName)
and create Chemical_T first.
SQL Fiddle with all tables created.

error ORA-02270: no matching unique or primary key for this column-list

I'm practicing a lab manual excercise in which I have to create 6 tables. Creation of 5 is
successful.
But one line is giving error
constraint GRADE_Designation_FK
FOREIGN KEY(Designation) References EMPLOYEE(Designation),
ERROR at line 7:
ORA-02270: no matching unique or primary key for this column-list
Queries of 2 linked tables are
create table EMPLOYEE
(
Empno number(4) constraint EMPLOYEE_Empno_PK PRIMARY KEY,
Name varchar2(10) not null,
Designation varchar2(50),
Qualification varchar2(10),
Joindate date
);
create table GRADE
(
Designation varchar2(50) constraint GRADE_Designation_PK PRIMARY KEY,
Grade number(2),
TotalPosts number(4),
PostsAvailable number(4),
constraint GRADE_Grade_CK check(Grade between 1 and 20),
constraint GRADE_PostsAvailable_CK check(PostsAvailable <= TotalPosts),
constraint GRADE_Designation_FK FOREIGN KEY(Designation) References EMPLOYEE(Designation)
);
Tried
create table GRADE
(
Designation varchar2(50) constraint GRADE_Designation_PK PRIMARY KEY,
Grade number(2),
TotalPosts number(4),
PostsAvailable number(4),
constraint GRADE_Grade_CK check(Grade between 1 and 20),
constraint GRADE_PostsAvailable_CK check(PostsAvailable <= TotalPosts)
);
create table EMPLOYEE
(
Empno number(4) constraint EMPLOYEE_Empno_PK PRIMARY KEY,
Name varchar2(10) not null,
Designation varchar2(50) NOT NULL UNIQUE,
Qualification varchar2(10),
Joindate date default sysdate
constraint EMPLOYEE_Designation_FK FOREIGN KEY(Designation) References GRADE(Designation),
);
Now new error
constraint EMPLOYEE_Designation_FK FOREIGN KEY(Designation) References GRADE(Designation)
*
ERROR at line 8:
ORA-02253: constraint specification not allowed here
You've got the constraint on the wrong table. You should create a foreign key on EMPLOYEE.DESIGNATION, referencing back to GRADE.DESIGNATION.
So your tables should look something like:
create table GRADE
(
Designation varchar2(50) constraint GRADE_Designation_PK PRIMARY KEY,
Grade number(2),
TotalPosts number(4),
PostsAvailable number(4),
constraint GRADE_Grade_CK check(Grade between 1 and 20),
constraint GRADE_PostsAvailable_CK check(PostsAvailable <= TotalPosts),
);
create table EMPLOYEE
(
Empno number(4) constraint EMPLOYEE_Empno_PK PRIMARY KEY,
Name varchar2(10) not null,
Designation varchar2(50)
constraint EMPLOYEE_FK1
REFERENCES GRADE(DESIGNATION),
Qualification varchar2(10),
Joindate date
);
Share and enjoy.
ORA-02270: no matching unique or primary key for this column-list
That error is very self explanatory and tells you what's wrong. In your case, you are trying to create foreign key on a non primary key column and so the error
constraint GRADE_Designation_FK FOREIGN KEY(Designation)
References EMPLOYEE(Designation)
<--Here
Designation in EMPLOYEE table is not a primary key and you can't create FK on a non primary key column. Your table creation rather should look like
create table GRADE
(
Designation varchar2(50) constraint GRADE_Designation_PK PRIMARY KEY,
employee_Empno number(4),
Grade number(2),
TotalPosts number(4),
PostsAvailable number(4),
constraint GRADE_Grade_CK check(Grade between 1 and 20),
constraint GRADE_PostsAvailable_CK check(PostsAvailable <= TotalPosts),
constraint GRADE_Designation_FK FOREIGN KEY(employee_Empno)
References EMPLOYEE(Empno));
It was the order of execution which has causes us this issue, make sure you have tables created with NOT NULL Enabled before adding those constraints to avoid this error.

Creating foreign keys from entites that are located in separate tables

I've been scratching my head at this for hours.
I have four tables Book, Author, Allocation and WorkSession
I need to make a constraint that the combination of the bid and authID exists in the Allocation table from the WorkSession table.
I tried to create a foreign key constraint like you would normally do but it won't work because the id's referenced are both foreign keys already and I can't create a new key as an identifier for the allocations table
CREATE TABLE Book(
bid NUMBER(4),
title VARCHAR2(30) NOT NULL,
SellingPrice NUMBER(6,2),
PRIMARY KEY (bid),
CONSTRAINT EM_SellingPrice CHECK(SellingPrice >= 0)
);
CREATE TABLE Author(
authID NUMBER(4),
fName VARCHAR2(30),
sName VARCHAR2(30),
PRIMARY KEY(authID),
CONSTRAINT EM_Name UNIQUE (fName,SName)
);
CREATE TABLE Allocation(
bid NUMBER(4),
authID NUMBER(4),
payRate NUMBER(6,2),
CONSTRAINT AL_PayRate CHECK(payRate >= 1 AND payRate < 80),
FOREIGN KEY(bid) REFERENCES Book(bid),
FOREIGN KEY(authID) REFERENCES Author(authID)
);
CREATE TABLE WorkSession(
bid NUMBER(4),
authID NUMBER(4),
WorkYear NUMBER(4),
WorkWeek NUMBER(2),
WorkHours NUMBER(4,2),
CONSTRAINT WY_Range CHECK(WorkYear > 2010 AND WorkYear < 2014),
CONSTRAINT WW_Range CHECK(WorkWeek >= 1 AND WorkWeek <= 52),
CONSTRAINT WH_Range CHECK(WorkHours >= 0.5 AND WorkHours <100),
CONSTRAINT FK_Check FOREIGN KEY(bid, AuthID) REFERENCES Allocation(bid, AuthID),
PRIMARY KEY(workYear, WorkWeek)
);
CREATE TABLE Allocation(
bid NUMBER(4),
authID NUMBER(4),
payRate NUMBER(6,2),
CONSTRAINT AL_PayRate CHECK(payRate >= 1 AND payRate < 80),
FOREIGN KEY(bid) REFERENCES Book(bid),
FOREIGN KEY(authID) REFERENCES Author(authID)
);
A foreign key constraint has to target something unique. You can do that with either a PRIMARY KEY constraint or a UNIQUE constraint on one or more columns. Your table "allocation", above, doesn't have either of those constraints.
If {bid, authid} are unique in the table "allocation", then you can declare PRIMARY KEY (bid, authid) in that table. A foreign key that REFERENCES allocation (bid, authid) should work then.