SQL syntax error on constraints - sql

Constraints and table not right, not sure where. Red lines under first constraints line and vehicle_code in SQL script:
create table hires (
vehicle_code_id varchar(25) primary key,
customer_id int not null,
employee_id int not null,
hired_from_date datetime not null,
hired_to_date datetime not null,
bond smallmoney not null,
constraint hires_pk primary key (hired_from_date),
constraint vehicle_code_fk foreign key (vehicle_code) references hires (vehicle_code_id),
constraint customer_fk foreign Key (customer_id) references customers (customer_id),
constraint employee_fk foreign key (employee_id) references employees (employee_id)
)

Related

SQL set FOREIGN KEY to a non unique value throws error in sql developer

I have a N:M situation, but I can't use any of the 2 non unique values as a Foreign Key can anyone help?? Both Platform_Id and Station_Id can not be set as a foreign key in the Platform_Host table.
CREATE TABLE Repair_Platform
(
Platform_Id INT NOT NULL,
Station_Id INT NOT NULL,
Mechanic_Id INT NOT NULL UNIQUE,
Validation_Num INT NOT NULL,
CONSTRAINT Platform_fk1
FOREIGN KEY (Station_Id) REFERENCES Repair_Station (Station_Id),
CONSTRAINT Platform_fk2
FOREIGN KEY (Mechanic_Id) REFERENCES Engineer (Engineer_Id),
CONSTRAINT Platform_pk
PRIMARY KEY (Station_Id, Platform_Id)
);
CREATE TABLE Platform_Host
(
Station_Id INT NOT NULL,
Platform_Id INT NOT NULL,
Vehicle_Id VARCHAR(8) NOT NULL,
DateTime DATE NOT NULL,
CONSTRAINT Host_fk1
FOREIGN KEY (Station_Id) REFERENCES Repair_Platform (Station_Id),
CONSTRAINT Host_fk2
FOREIGN KEY (Vehicle_Id) REFERENCES Vehicle (License_Plate),
CONSTRAINT Host_fk3
FOREIGN KEY (Platform_Id) REFERENCES Repair_Platform (Platform_Id)
);
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
You need to reference the whole primary key of Repair_Platform - like this:
CREATE TABLE Platform_Host
(
-- columns
-- constraints
CONSTRAINT Host_fk3
FOREIGN KEY (StationId, Platform_Id)
REFERENCES Repair_Platform (StationId, Platform_Id)
);
You cannot reference only parts of a primary key - it's an all or nothing deal.

SQL Script File is failing but not showing an error

I have ran this Script File on Oracle Application Express and it does not create my tables and does not state that I have errors. If you can't help that is okay, but I have been at this for hours and cannot figure out why it is not working
Here is my Script File:
CREATE TABLE GUEST_T
(GUEST_ID NUMBER NOT NULL,
GUEST_NAME VARCHAR(25),
GUEST_ADDRESS VARCHAR(30),
CONSTRAINT GUEST_PK PRIMARY KEY (GUEST_ID));
CREATE TABLE COMPANY_T
(GUEST_ID NUMBER NOT NULL,
GUEST_NAME VARCHAR(25),
COMPANY_NAME VARCHAR(25),
ADDRESS VARCHAR(30),
NO_OF_GUESTS INT,
CONSTRAINT COMPANY_PK PRIMARY KEY (GUEST_ID),
CONSTRAINT COMPANY_FK FOREIGN KEY (GUEST_ID) REFERENCES GUEST_T(GUEST_ID));
CREATE TABLE ACCOMMODATION_T
(ACCOMMODATION_ID NUMBER NOT NULL,
ACCOMMODATION_TYPE VARCHAR(25),
PRICE DECIMAL (6,2),
CONSTRAINT ACCOMMODATION_PK PRIMARY KEY (ACCOMMODATION_ID));
CREATE TABLE EMPLOYEE_T
(EMPLOYEE_ID NUMBER NOT NULL,
EMPLOYEE_NAME VARCHAR(25),
HOURS_WORKED INT,
CONSTRAINT EMPLOYEE_PK PRIMARY KEY (EMPLOYEE_ID));
CREATE TABLE RECEPTIONIST_T
(EMPLOYEE_ID NUMBER NOT NULL,
EMPLOYEE_NAME VARCHAR(25),
HOURS_WORKED INT,
HOURLY_WAGE DECIMAL (4,2),
CONSTRAINT RECEPTIONIST_PK PRIMARY KEY (EMPLOYEE_ID),
CONSTRAINT EMPLOYEE_FK FOREIGN KEY (EMPLOYEE_ID) REFERENCES EMPLOYEE_T(EMPLOYEE_ID));
CREATE TABLE MANAGER_T
(EMPLOYEE_ID NUMBER NOT NULL,
EMPLOYEE_NAME VARCHAR(25),
HOURS_WORKED INT,
SALARY DECIMAL (10,2)
CONSTRAINT MANAGER_PK PRIMARY KEY (EMPLOYEE_ID),
CONSTRAINT EMPLOYEE_FK FOREIGN KEY (EMPLOYEE_ID) REFERENCES EMPLOYEE_T(EMPLOYEE_ID));
CREATE TABLE ACCOMMODATION_REQUEST_T
(ACCOMMODATION_ID NUMBER NOT NULL,
GUEST_ID NUMBER NOT NULL,
EMPLOYEE_ID NUMBER NOT NULL,
TIME REQUESTED NUMBER,
DATE_OF_USE DATE DEFAULTSYSDATE,
CONSTRAINT ACCOMMODATION_REQUEST_PK PRIMARY KEY (ACCOMMODATION_ID, GUEST_ID, EMPLOYEE_ID),
CONSTRAINT ACCOMMODATION_REQUEST_FK1 FOREIGN KEY (ACCOMMODATION_ID) REFERENCES ACCOMMODATION_T(ACCOMMODATION_ID),
CONSTRAINT ACCOMMODATION_REQUEST_FK2 FOREIGN KEY (GUEST_ID) REFERENCES GUEST_T(GUEST_ID),
CONSTRAINT ACCOMMODATION_REQUEST_FK3 FOREIGN KEY (EMPLOYEE_ID) REFERENCES EMPLOYEE_T(EMPLOYEE_ID));
CREATE TABLE ROOM_T
(ROOM_NO NUMBER NOT NULL,
FLOOR_NO NUMBER,
ROOM_PRICE DECIMAL (8,2),
ROOM_STATUS VARCHAR(20) CHECK (ROOM_STATUS IN (‘Vacant’, ‘Occupied’)),
CONSTRAINT ROOM_PK PRIMARY KEY (ROOM_NO),
CONSTRAINT ROOM_FK FOREIGN KEY (FLOOR_NO) REFERENCES FLOOR_T(FLOOR_NO));
CREATE TABLE DOUBLE_ROOM_T
(ROOM_NO NUMBER NOT NULL,
ROOM_PRICE DECIMAL (8,2),
ROOM_STATUS VARCHAR(20) CHECK (ROOM_STATUS IN (‘Vacant’, ‘Occupied’)),
ADJOINED VARCHAR(5) CHECK (ADJOINED IN (‘Yes’, ’No’)),
CONSTRAINT DOUBLE_ROOM_PK PRIMARY KEY (ROOM_NO),
CONSTRAINT DOUBLE_ROOM_FK1 FOREIGN KEY (ROOM_NO) REFERENCES ROOM_T (ROOM_NO),
CONSTRAINT DOUBLE_ROOM_FK2 FOREIGN KEY (FLOOR_NO) REFERENCES FLOOR_T (FLOOR_NO));
CREATE TABLE RESERVATION_T
(ROOM_NO NUMBER NOT NULL,
GUEST_ID NUMBER NOT NULL,
EMPLOYEE_ID NUMBER NOT NULL,
CHECK_IN_DATE DATE DEFAULTSYSDATE,
CHECK_OUT_DATE DATE DEFAULTSYSDATE,
NO_OF_ROOMS INT,
CONSTRAINT RESERVATION_PK PRIMARY KEY (ROOM_NO, GUEST_ID, EMPLOYEE_ID),
CONSTRAINT RESERVATION_FK1 FOREIGN KEY (ROOM_NO) REFERENCES ROOM_T(ROOM_NO),
CONSTRAINT RESERVATION_FK2 FOREIGN KEY (GUEST_ID) REFERENCES GUEST_T(GUEST_ID),
CONSTRAINT RESERVATION_FK3 FOREIGN KEY (EMPLOYEE_ID) REFERENCES EMPLOYEE_T(EMPLOYEE_ID));
CREATE TABLE FLOOR_T
(FLOOR_NO NUMBER NOT NULL,
NO_OF_ROOMS INT,
CONSTRAINT FLOOR_PK PRIMARY KEY (FLOOR_NO));
CREATE TABLE FACILITY_T
(FACILITY_ID NUMBER NOT NULL,
FACILITY_NAME VARCHAR(25),
CONSTRAINT FACILITY_PK PRIMARY KEY (FACILITY_ID));
I have run this Script File on Oracle Application Express and it does not create my tables and does not state that I have errors. If you can't help that is okay, but I have been at this for hours and cannot figure out why it is not working.
There are a lot of issues in your script (and they do show up when the scripts runs). The most proeminent ones are:
the same constraint name is used in several tables; a constraint name must be unique in a schema, you can prefix them with the table name to avoid clashes
various typos : missing underscore, missing spaces, missing commas
funky quotes ‘’ instead of regular quotes
wrong table creation sequence: a parent table must be created before its dependant tables
side note: you want to use VARCHAR2, that Oracle recommends to replace VARCHAR
Here is a new version of your script that works fine in this DB fiddle. All the changes are commented:
CREATE TABLE GUEST_T (
GUEST_ID NUMBER NOT NULL,
GUEST_NAME VARCHAR2(25),
GUEST_ADDRESS VARCHAR2(30),
CONSTRAINT GUEST_PK PRIMARY KEY (GUEST_ID)
);
CREATE TABLE COMPANY_T (
GUEST_ID NUMBER NOT NULL,
GUEST_NAME VARCHAR2(25),
COMPANY_NAME VARCHAR2(25),
ADDRESS VARCHAR2(30),
NO_OF_GUESTS INT,
CONSTRAINT COMPANY_PK PRIMARY KEY (GUEST_ID),
CONSTRAINT COMPANY_FK FOREIGN KEY (GUEST_ID) REFERENCES GUEST_T(GUEST_ID)
);
CREATE TABLE ACCOMMODATION_T (
ACCOMMODATION_ID NUMBER NOT NULL,
ACCOMMODATION_TYPE VARCHAR2(25),
PRICE DECIMAL (6,2),
CONSTRAINT ACCOMMODATION_PK PRIMARY KEY (ACCOMMODATION_ID)
);
CREATE TABLE EMPLOYEE_T (
EMPLOYEE_ID NUMBER NOT NULL,
EMPLOYEE_NAME VARCHAR2(25),
HOURS_WORKED INT,
CONSTRAINT EMPLOYEE_PK PRIMARY KEY (EMPLOYEE_ID)
);
CREATE TABLE RECEPTIONIST_T (
EMPLOYEE_ID NUMBER NOT NULL,
EMPLOYEE_NAME VARCHAR2(25),
HOURS_WORKED INT,
HOURLY_WAGE DECIMAL (4,2),
CONSTRAINT RECEPTIONIST_PK PRIMARY KEY (EMPLOYEE_ID),
CONSTRAINT RECEPTIONIST_T_EMPLOYEE_FK -- constraint name must be unique
FOREIGN KEY (EMPLOYEE_ID) REFERENCES EMPLOYEE_T(EMPLOYEE_ID)
);
CREATE TABLE MANAGER_T (
EMPLOYEE_ID NUMBER NOT NULL,
EMPLOYEE_NAME VARCHAR2(25),
HOURS_WORKED INT,
SALARY DECIMAL (10,2), -- missing comma here
CONSTRAINT MANAGER_PK PRIMARY KEY (EMPLOYEE_ID),
CONSTRAINT MANAGER_T_EMPLOYEE_FK -- constraint name must be unique
FOREIGN KEY (EMPLOYEE_ID) REFERENCES EMPLOYEE_T(EMPLOYEE_ID)
);
CREATE TABLE ACCOMMODATION_REQUEST_T (
ACCOMMODATION_ID NUMBER NOT NULL,
GUEST_ID NUMBER NOT NULL,
EMPLOYEE_ID NUMBER NOT NULL,
TIME_REQUESTED NUMBER, -- missing underscore between TIME and REQUESTED
DATE_OF_USE DATE DEFAULT SYSDATE, -- missing space between DEFAULT and SYSDATE
CONSTRAINT ACCOMMODATION_REQUEST_PK PRIMARY KEY (ACCOMMODATION_ID, GUEST_ID, EMPLOYEE_ID),
CONSTRAINT ACCOMMODATION_REQUEST_FK1 FOREIGN KEY (ACCOMMODATION_ID) REFERENCES ACCOMMODATION_T(ACCOMMODATION_ID),
CONSTRAINT ACCOMMODATION_REQUEST_FK2 FOREIGN KEY (GUEST_ID) REFERENCES GUEST_T(GUEST_ID),
CONSTRAINT ACCOMMODATION_REQUEST_FK3 FOREIGN KEY (EMPLOYEE_ID) REFERENCES EMPLOYEE_T(EMPLOYEE_ID)
);
-- must be created before the dependant tables (ROOM_T, DOUBLE_ROOM_T, ...)
CREATE TABLE FLOOR_T (
FLOOR_NO NUMBER NOT NULL,
NO_OF_ROOMS INT,
CONSTRAINT FLOOR_PK PRIMARY KEY (FLOOR_NO)
);
CREATE TABLE ROOM_T (
ROOM_NO NUMBER NOT NULL,
FLOOR_NO NUMBER,
ROOM_PRICE DECIMAL (8,2),
ROOM_STATUS VARCHAR2(20) CHECK (ROOM_STATUS IN ('Vacant', 'Occupied')), -- funky quotes ‘’
CONSTRAINT ROOM_PK PRIMARY KEY (ROOM_NO),
CONSTRAINT ROOM_FK FOREIGN KEY (FLOOR_NO) REFERENCES FLOOR_T(FLOOR_NO)
);
CREATE TABLE DOUBLE_ROOM_T (
ROOM_NO NUMBER NOT NULL,
ROOM_PRICE DECIMAL (8,2),
ROOM_STATUS VARCHAR2(20) CHECK (ROOM_STATUS IN ('Vacant', 'Occupied')), -- funky quotes ‘’
ADJOINED VARCHAR2(5) CHECK (ADJOINED IN ('Yes', 'No')), -- funky quote ‘’
CONSTRAINT DOUBLE_ROOM_PK PRIMARY KEY (ROOM_NO),
CONSTRAINT DOUBLE_ROOM_FK1 FOREIGN KEY (ROOM_NO) REFERENCES ROOM_T (ROOM_NO)
-- CONSTRAINT DOUBLE_ROOM_FK2 FOREIGN KEY (FLOOR_NO) REFERENCES FLOOR_T (FLOOR_NO) -- there is no such column
);
CREATE TABLE RESERVATION_T (
ROOM_NO NUMBER NOT NULL,
GUEST_ID NUMBER NOT NULL,
EMPLOYEE_ID NUMBER NOT NULL,
CHECK_IN_DATE DATE DEFAULT SYSDATE, -- missing space between DEFAULT and SYSDATE
CHECK_OUT_DATE DATE DEFAULT SYSDATE, -- missing space between DEFAULT and SYSDATE
NO_OF_ROOMS INT,
CONSTRAINT RESERVATION_PK PRIMARY KEY (ROOM_NO, GUEST_ID, EMPLOYEE_ID),
CONSTRAINT RESERVATION_FK1 FOREIGN KEY (ROOM_NO) REFERENCES ROOM_T(ROOM_NO),
CONSTRAINT RESERVATION_FK2 FOREIGN KEY (GUEST_ID) REFERENCES GUEST_T(GUEST_ID),
CONSTRAINT RESERVATION_FK3 FOREIGN KEY (EMPLOYEE_ID) REFERENCES EMPLOYEE_T(EMPLOYEE_ID)
);
CREATE TABLE FACILITY_T (
FACILITY_ID NUMBER NOT NULL,
FACILITY_NAME VARCHAR2(25),
CONSTRAINT FACILITY_PK PRIMARY KEY (FACILITY_ID)
);

Database constraint over multiple tables

Say I have the following tables:
CREATE TABLE [Weeks]
(
[Id] INT NOT NULL IDENTITY,
CONSTRAINT [PK_Weeks] PRIMARY KEY ([Id])
);
CREATE TABLE [Days]
(
[Id] INT NOT NULL IDENTITY,
[WeekId] INT NULL,
CONSTRAINT [PK_Days] PRIMARY KEY ([Id]),
CONSTRAINT [FK_Days_Weeks_WeekId]
FOREIGN KEY ([WeekId]) REFERENCES [Weeks] ([Id])
);
CREATE TABLE [ReplacedDayInWeek]
(
[Id] INT NOT NULL IDENTITY,
[WeekId] INT NOT NULL,
[DayId] INT NOT NULL,
[ReplacedDayId] INT NOT NULL,
CONSTRAINT [PK_ReplacedDayInWeek] PRIMARY KEY ([Id]),
CONSTRAINT [FK_ReplacedDayInWeek_Days_DayId]
FOREIGN KEY ([DayId]) REFERENCES [Days] ([Id]),
CONSTRAINT [FK_ReplacedDayInWeek_Weeks_WeekId]
FOREIGN KEY ([WeekId]) REFERENCES [Weeks] ([Id]),
CONSTRAINT [FK_ReplacedDayInWeek_Weeks_ReplacedWeekId]
FOREIGN KEY ([ReplacedWeekId]) REFERENCES [Weeks] ([Id])
);
The table ReplacedDayInWeek contains a day in a specific week that's replaced by another day.
How can I create a SQL constraint (or perhaps another SQL based solution) that makes sure I can only insert rows into DayInWeek with a DayId that's part of the same week as WeekId?
I'm looking for a solution with the least amount of changes to the source database. I'd prefer an additional table or table changes above stored procedures.
This data structure makes no sense to me. You have the mapping between days and weeks in two tables.
You should really only be storing the week in one table and looking it up in the other.
That said, you can do what you want using an additional constraint on day/week between the two tables:
CREATE TABLE [Days]
(
[Id] INT NOT NULL IDENTITY,
[WeekId] INT NULL,
CONSTRAINT [PK_Days] PRIMARY KEY ([Id]),
CONSTRAINT [FK_Days_Weeks_WeekId]
FOREIGN KEY ([WeekId]) REFERENCES [Weeks] ([Id]),
CONSTRAINT UNQ_Days_WeekId_Id UNIQUE (WeekId, Id)
);
CREATE TABLE [DaysInWeek]
(
[Id] INT NOT NULL IDENTITY,
[WeekId] INT NOT NULL,
[DayId] INT NOT NULL,
CONSTRAINT [PK_DaysInWeek] PRIMARY KEY([Id]),
CONSTRAINT [FK_DaysInWeek_Days_WeekId_DayId]
FOREIGN KEY (WeekId, DayId) REFERENCES Days(WeekId, Id),
CONSTRAINT [FK_DaysInWeek_Weeks_WeekId]
FOREIGN KEY ([WeekId]) REFERENCES [Weeks] ([Id])
);

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.

Primary key composed of two foreign keys? Oracle

I have a question regarding a table creation. I want to combine the attributes of "Ono" and "Pno" into a primary key for a new table. These are both foreign keys, each from different tables. Do I just use a CONSTRAINT Ono_Pno_PK PRIMARY KEY (Ono,Pno)?
what I have used so far:
CREATE TABLE ODetails
(
Ono Number Not Null,
Pno Number Not Null,
Qty Number(3) Not Null,
Creation_Date Date Not Null,
Created_By VARCHAR(10) Not Null,
Last_Update_Date Date Not Null,
Last_Updated_By VARCHAR2(10) Not Null,
CONSTRAINT Ono_FK FOREIGN KEY (Ono) REFERENCES Orders (Ono),
CONSTRAINT Pno_FK FOREIGN KEY (Pno) REFERENCES Parts (Pno)
);
just add this line after the constraints,
CONSTRAINT tb_PK PRIMARY KEY (Ono, Pno)