SQL Script File is failing but not showing an error - sql

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)
);

Related

Simple database with 3 tables and "no matching unique or primary key for this column"

I have three tables, two are created independently, and the third one is created to include some inputs from the first two. First two tables have no problems, however, when I try to create the third one, I get an error:
Error report -
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
The thing is, I created the third table by copy/pasting the column names/definitions right from the first two tables, yet I still get this ridiculous error message. Now I wonder if the order of the columns and the especially the order of constrains is important.
The tables:
comm_Customers
CREATE TABLE comm_Customers (
custID NUMBER(6) NOT NULL,
FirstName VARCHAR2(10) NOT NULL,
LastName VARCHAR2(15) NOT NULL,
HomeCountry VARCHAR2(2) NOT NULL,
HomeState_Prov VARCHAR2(2) NOT NULL,
HomeCity VARCHAR2(20) NOT NULL,
HomeAddress VARCHAR2(25) NOT NULL,
Phone NUMBER(10) NOT NULL,
Email VARCHAR2(15) NOT NULL,
ShippCountry VARCHAR2(2) NOT NULL,
ShippState_Prov VARCHAR2(2) NOT NULL,
ShippCity VARCHAR2(10) NOT NULL,
ShippAddress VARCHAR2(15) NOT NULL,
CONSTRAINT comm_customers_custid_pk PRIMARY KEY (custID)
);
comm_Items
CREATE TABLE comm_Items (
itemID NUMBER(4) NOT NULL,
ItemCat VARCHAR2(3) NOT NULL,
ItemQty NUMBER(4) NOT NULL,
SalePrice NUMBER(6,2) NOT NULL,
CostPrice NUMBER(6,2) NOT NULL,
ItemDesc VARCHAR2(15),
CONSTRAINT comm_items_itemid_pk PRIMARY KEY (itemID)
);
comm_Orders which gives the error
CREATE TABLE comm_Orders (
orderID NUMBER(10) NOT NULL,
OrderQty NUMBER(4) NOT NULL,
OrderDate DATE NOT NULL,
Shipped VARCHAR2(1),
ShippedDate DATE,
custID NUMBER(6) NOT NULL,
Phone NUMBER(10) NOT NULL,
Email VARCHAR2(15) NOT NULL,
ShippCountry VARCHAR2(2) NOT NULL,
ShippState_Prov VARCHAR2(2) NOT NULL,
ShippCity VARCHAR2(10) NOT NULL,
ShippAddress VARCHAR2(15) NOT NULL,
itemID NUMBER(4) NOT NULL,
SalePrice NUMBER(6,2) NOT NULL,
CONSTRAINT comm_order_orderid_pk PRIMARY KEY (orderID),
CONSTRAINT comm_order_custid_fk FOREIGN KEY (custID)
REFERENCES comm_Customers(custID),
CONSTRAINT comm_order_phone_fk FOREIGN KEY (Phone)
REFERENCES comm_Customers(Phone),
CONSTRAINT comm_order_email_fk FOREIGN KEY (Email)
REFERENCES comm_Customers(Email),
CONSTRAINT comm_order_shippcountry_fk FOREIGN KEY (ShippCountry)
REFERENCES comm_Customers(ShippCountry),
CONSTRAINT comm_order_shippstate_prov_fk FOREIGN KEY (ShippState_Prov)
REFERENCES comm_Customers(ShippState_Prov),
CONSTRAINT comm_order_shippcity_fk FOREIGN KEY (ShippCity)
REFERENCES comm_Customers(ShippCity),
CONSTRAINT comm_order_shippaddress_fk FOREIGN KEY (ShippAddress)
REFERENCES comm_Customers(ShippAddress),
CONSTRAINT comm_order_itemid_fk FOREIGN KEY (itemID)
REFERENCES comm_Items(itemID),
CONSTRAINT comm_order_saleprice_fk FOREIGN KEY (SalePrice)
REFERENCES comm_Items(SalePrice)
ON DELETE CASCADE,
CONSTRAINT comm_order_shipped_chk CHECK (Shipped IN ('Y','N'))
);
The references to non-primary key columns of customers and items do raise the error.
Bottom-line, you should not be duplicating the information from the referential tables. A single foreign key is sufficient.
So:
CREATE TABLE comm_Orders (
orderID NUMBER(10) NOT NULL,
OrderQty NUMBER(4) NOT NULL,
OrderDate DATE NOT NULL,
Shipped VARCHAR2(1),
ShippedDate DATE,
custID NUMBER(6) NOT NULL,
itemID NUMBER(4) NOT NULL,
CONSTRAINT comm_order_orderid_pk PRIMARY KEY (orderID),
CONSTRAINT comm_order_custid_fk FOREIGN KEY (custID) REFERENCES comm_Customers(custID),
CONSTRAINT comm_order_itemid_fk FOREIGN KEY (itemID) REFERENCES comm_Items(itemID),
CONSTRAINT comm_order_shipped_chk CHECK (Shipped IN ('Y','N'))
);
Then, whenever you need to recover an information from a referential table, you join it using the foreign key. Say you want the phone of a customer:
select o.*, c.phone
from comm_orders o
inner join comm_customers c on c.custid = o.custid

SQL syntax error on constraints

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)
)

"unknown command" shown when creating a foreign key constraint

The following script produces an error:
CREATE TABLE BOTTLE
(
Bottle_ID VARCHAR(30) NOT NULL,
BottleSize NUMBER(10,0) ,
Shape VARCHAR(30) ,
GlassColor VARCHAR(30) ,
BottleInventory NUMBER(10,0) ,
CostPerBottle NUMBER(5,2) ,
constraint BOTTLE_PK PRIMARY KEY (Bottle_ID)
);
create table BOTTLE_VENDOR
(
Vendor_ID VARCHAR(30) not null,
VendorName VARCHAR(20),
Vendor_Straddr1 VARCHAR(100),
Vendor_Straddr2 VARCHAR(100),
Vendor_City VARCHAR(20),
Vendor_State VARCHAR(20),
Vendor_Zip CHAR(5),
Vendor_Phone VARCHAR(20),
PrincipalContact VARCHAR(30),
constraint pk_BOTTLE_VENDOR primary key (Vendor_ID)
);
create table BOTTLE_ORDER
(
Bottle_Order_ID VARCHAR(30) not null,
BottleOrderDate DATE,
Vendor_ID VARCHAR(30),
constraint pk_BOTTLE_ORDER primary key (Bottle_Order_ID),
constraint fk_BOTTLE_ORDER foreign key (Vendor_ID) references BOTTLE_VENDOR(Vendor_ID)
);
create table SHIPMENT
(
Shipment_ID VARCHAR(30) not null,
ShipmentDate DATE,
ReceivedQuantity INTEGER,
ReceivedDate DATE,
Bottle_Order_ID VARCHAR(30),
constraint pk_SHIPMENT primary key (Shipment_ID),
constraint fk_SHIPMENT foreign key (Bottle_Order_ID) references BOTTLE_ORDER(Bottle_Order_ID)
);
create table BOTTLE_ORDER_LINE
(
Bottle_Order_ID VARCHAR(30) not null,
Bottle_ID VARCHAR(30) not null,
BottleOrderQuantity INTEGER,
ActualPricePerBottle NUMBER(5,2),
constraint pk_BOTTLE_ORDER_LINE primary key (Bottle_Order_ID,Bottle_ID),
constraint fk_BOTTLE_ORDER_LINE foreign key (Bottle_Order_ID) references BOTTLE_ORDER(Bottle_Order_ID),
constraint fk_BOTTLE_ORDER_LINE2 foreign key (Bottle_Order_ID) references BOTTLE(Bottle_ID)
);
Here is what exactly shown:
Error starting at line : 37 in command - constraint fk_SHIPMENT foreign key (Bottle_Order_ID) references BOTTLE_ORDER(Bottle_Order_ID)
Error report -
Unknown Command
The error drives me crazy and don't know how to deal with it.
The following line (the last line you've posted) does not match your table definitions:
constraint fk_BOTTLE_ORDER_LINE2 foreign key (Bottle_Order_ID) references BOTTLE(Bottle_ID)
it should read:
constraint fk_BOTTLE_ORDER_LINE2 foreign key (Bottle_ID) references BOTTLE(Bottle_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)