Trying to run script through Oracle 11g - sql

I am trying to run SQL statements in the Oracle 11g Express edition, where I am to create tables. Here is my SQL code:
CREATE TABLE STORE
(
StoreID INT PRIMARY KEY,
StoreName VARCHAR2(30) NOT NULL,
City VARCHAR2(30) NOT NULL,
Country VARCHAR2(30) NOT NULL CHECK Country in ('China','Egypt','United States','Spain','New Zealand','Mexico','Africa'),
Phone VARCHAR2(30) NOT NULL,
Fax VARCHAR2(30),
Email VARCHAR2(50) UNIQUE,
Contact VARCHAR2(30) NOT NULL,
UNIQUE (StoreName, City)
);
CREATE TABLE PURCHASE_ITEM
(
PurchaseItemID INT PRIMARY KEY,
StoreID INT NOT NULL REFERENCES STORE(StoreID) ON DELETE CASCADE ON UPDATE CASCADE,
"Date" DATE NOT NULL,
Description VARCHAR2(30) NOT NULL,
Category VARCHAR2(30),
PriceUsed NUMBER(15, 2)
);
CREATE SEQUENCE pur_seq
START WITH 500
INCREMENT BY 5;
CREATE OR REPLACE TRIGGER Purchase
BEFORE INSERT ON PURCHASE_ITEM
FOR EACH ROW
BEGIN
SELECT pur_seq.NEXTVAL
INTO :new.PurchaseItemID
FROM dual;
END;
CREATE TABLE SHIPPER
(
ShipperID INT PRIMARY KEY,
ShipperName VARCHAR2(30) NOT NULL,
Phone VARCHAR2(30) NOT NULL,
Fax VARCHAR2(30),
Email VARCHAR2(50) UNIQUE,
Contact VARCHAR2(30) NOT NULL
);
CREATE TABLE SHIPMENT
(
ShipmentID INT PRIMARY KEY Auto Increment,
ShipperID INT NOT NULL REFERENCES SHIPPER(ShipperID) ON DELETE CASCADE ON UPDATE CASCADE,
ShipperInvoiceNumber INT NOT NULL UNIQUE,
Origin VARCHAR2(30) NOT NULL,
Destination VARCHAR2(30) NOT NULL,
DepartureDate DATE,
ArrivalDate DATE
);
ALTER TABLE SHIPMENT AUTO_INCREMENT = 100;
CREATE TABLE SHIPMENT_ITEM
(
ShipmentID INT NOT NULL REFERENCES SHIPMENT(ShipmentID) ON DELETE CASCADE ON UPDATE CASCADE,
ShipmentItemID INT NOT NULL,
PurchaseItemID INT NOT NULL REFERENCES PURCHASE_ITEM(PurchaseItemID) ON DELETE CASCADE ON UPDATE CASCADE,
InsuredValue NUMBER(15, 2) NOT NULL defaut 100,
PRIMARY KEY (ShipmentID, ShipmentItemID)
);
It only ends up processing 4 statements and I keep getting these error messages:
CREATE TABLE STORE ( StoreID INT PRIMARY K - ORA-00906: missing left parenthesis
CREATE TABLE PURCHASE_ITEM ( PurchaseItemID INT - ORA-00907: missing right parenthesis
CREATE SEQUENCE pur_seq START WITH 500 INCREMENT BY 5 - ORA-00955: name is already used by an existing object
CREATE OR REPLACE TRIGGER Purchase BEFORE INSERT ON PURCHASE - ORA-00942: table or view does not exist
I am wholly unfamiliar with Oracle 11g. I am unsure if I am using the correct application in it for my assignment. I am only going by these instructions:
"For this assignment you are to write scripts to create tables and insert records. In oracle 11g I don’t want you to use the tools to generate the tables, you are required to write scripts to create the tables and records and will need to include the scripts for your submission."
Please, what am I doing wrong?

Let me summarize the problems with your scripts
First you have to enclose the check constraint with braces like below
CREATE TABLE STORE
(
StoreID INT PRIMARY KEY,
StoreName VARCHAR2(30) NOT NULL,
City VARCHAR2(30) NOT NULL,
Country VARCHAR2(30) NOT NULL CHECK (Country in ('China','Egypt','United States','Spain','New Zealand','Mexico','Africa')),
Phone VARCHAR2(30) NOT NULL,
Fax VARCHAR2(30),
Email VARCHAR2(50) UNIQUE,
Contact VARCHAR2(30) NOT NULL,
UNIQUE (StoreName, City)
);
Second, there is no ON UPDATE CASCADE in Oracle 11g so you need to remove it from the CREATE TABLE statement
Third, there is no Auto increment in Oracle 11G for columns So refer this SO for a workaround
Please let me know with these corrections whether your issue is resolved

Related

Creating a audit trigger which update a audit table automatically

My tables are
Book
CREATE TABLE Book
(
Bk_id CHAR(06)NOT NULL,
BK_Name VARCHAR(60)NOT NULL,
Author VARCHAR(30)NOT NULL,
Price NUMERIC(03)NOT NULL,
No_of_copies NUMERIC(02)NOT NULL,
CONSTRAINT Book_PK PRIMARY KEY (Bk_id)
);
Location
CREATE TABLE Location
(
Loc_id CHAR(06)NOT NULL,
Loc_Name VARCHAR(15)NOT NULL,
Stock NUMERIC(02)NOT NULL,
CONSTRAINT Location_PK PRIMARY KEY (Loc_id)
);
Customer
CREATE TABLE Customer
(
Cus_id CHAR(06)NOT NULL,
Cus_Name VARCHAR(25)NOT NULL,
Gender VARCHAR(06)NOT NULL,
TP CHAR(12)NOT NULL,
Address VARCHAR(40)NOT NULL,
CONSTRAINT Customer_PK PRIMARY KEY (Cus_id)
);
Copy
CREATE TABLE Copy
(
Copy_id CHAR(06)NOT NULL,
Bk_id CHAR(06)NOT NULL,
Loc_id CHAR(06)NOT NULL,
Opinion CHAR(02)NOT NULL,
CONSTRAINT pk_Copy PRIMARY KEY (Copy_id),
CONSTRAINT fk_Copy_Bk_id_FK FOREIGN KEY (Bk_id) REFERENCES Book(Bk_id),
CONSTRAINT fk_Copy_Loc_id_FK FOREIGN KEY (Loc_id) REFERENCES Location(Loc_id)
);
Borrow
CREATE TABLE Borrow
(
Cus_evo NUMERIC(02)NOT NULL,
B_Date DATE NOT NULL,
R_Date DATE NOT NULL,
Fee NUMERIC(03)NOT NULL,
Copy_id CHAR(06)NOT NULL,
Cus_id CHAR(06)NOT NULL,
CONSTRAINT pk_Borrow PRIMARY KEY (Cus_id,Copy_id),
CONSTRAINT fk_Borrow_Copy_id_FK FOREIGN KEY (Copy_id) REFERENCES Copy(Copy_id),
CONSTRAINT fk_Borrow_Cus_id_FK FOREIGN KEY (Cus_id) REFERENCES Customer(Cus_id)
);
Audit_Table
Create table Audit_Table
(
Cus_Name VARCHAR(25)NOT NULL,
BK_Name VARCHAR(60)NOT NULL,
B_Date DATE NOT NULL,
Loc_Name VARCHAR(15)NOT NULL,
Cus_evo NUMERIC(02)NOT NULL
);
If a customer gives a zero evaluationCus_evo=0, the details of their Borrowing (Cus_Name from CUSTOMER, the BK_Name from Book, B_Date from Borrow, Loc_Name of the copy from Location and Cus_evo from Borrow) must be placed in an audit table.
The trigger that I created:
CREATE OR REPLACE TRIGGER "AUDIT_TRIGGER"
BEFORE
INSERT OR UPDATE ON Borrow
FOR EACH ROW
WHEN (new.Cus_evo=0)
BEGIN
INSERT INTO Audit_Table
VALUES (:OLD.Cus_Name, :OLD.BK_Name, :OLD.B_Date, :OLD.Loc_Name, :OLD.Cus_evo);
END;
/
I get this error:
Errors: TRIGGER AUDIT_TRIGGER
Line/Col: 3/9 PLS-00049: bad bind variable 'OLD.CUS_NAME'
Line/Col: 3/24 PLS-00049: bad bind variable 'OLD.BK_NAME'
Line/Col: 3/51 PLS-00049: bad bind variable 'OLD.LOC_NAME'
You can not use old and new values from other tables only from table Borrwo when you are creating trigger
You need to specify if you want to check new or old value in WHEN clause
CREATE OR REPLACE TRIGGER "AUDIT_TRIGGER"
BEFORE INSERT OR UPDATE ON Borrow --I have removed double quotes
FOR EACH ROW
WHEN (new.Cus_evo = 0) -- I have added new. before the name of the column
BEGIN
INSERT INTO Audit_Table
VALUES (:OLD.Fee, :OLD.Copy_id, :OLD.Cus_id, :OLD.B_Date, :OLD.Cus_evo);
-- I have replaced column names from other tables with column names
-- from table "Borrow"
END;
/
Here is a demo:
DEMO
In this demo I have removed
CONSTRAINT fk_Borrow_Copy_id_FK FOREIGN KEY (Copy_id) REFERENCES Copy(Copy_id),
from table Borrow spec because it references on the table Copy that we do not have here in your question.
After I have read the comment from #Belayer I have concluded you will need two triggers like this:
CREATE OR REPLACE TRIGGER "AUDIT_TRIGGER"
BEFORE INSERT ON Borrow
FOR EACH ROW
when (new.Cus_evo = 0)
BEGIN
INSERT INTO Audit_Table
VALUES (:new.Copy_id, :new.Copy_id, :new.B_Date, :new.Cus_id, :new.Cus_evo);
END;
/
CREATE OR REPLACE TRIGGER "AUDIT_TRIGGER2"
BEFORE UPDATE ON Borrow
FOR EACH ROW
when (OLD.Cus_evo = 0)
BEGIN
INSERT INTO Audit_Table
VALUES (:OLD.Copy_id, :OLD.Copy_id, :OLD.B_Date, :OLD.Cus_id, :OLD.Cus_evo);
END;
/
Here is a demo with demonstration:
DEMO

How can I write simple data mining queries for the following schemas?

For the following given schema, can I please guided on how to write simple Data mining queries using oracle with sqlplus?
CREATE TABLE Location(Location_id NUMBER(5) NOT NULL, Location_name varchar(15) NOT NULL,PRIMARY KEY (Location_id));
CREATE TABLE Customer(customer_id NUMBER(5) NOT NULL, customer_name varchar(15) NOT NULL, customer_credit NUMBER(6) NOT NULL, PRIMARY KEY (customer_id));
CREATE TABLE Product(product_id NUMBER(5) NOT NULL, product_name varchar(10) NOT NULL, product_price NUMBER(6) NOT NULL, product_quantity NUMBER(6) NOT NULL, PRIMARY KEY (product_id));
CREATE TABLE Supplier(supplier_id NUMBER(5) NOT NULL, supplier_name varchar(15) NOT NULL, supplier_quantity NUMBER(5) NOT NULL,PRIMARY KEY (supplier_id));
CREATE TABLE Store (customer_id NUMBER(5) NOT NULL, supplier_id NUMBER(5) NOT NULL, product_id NUMBER(5) NOT NULL, location_id NUMBER(5) NOT NULL,sale NUMBER(9) NOT NULL,category varchar(9) NOT NULL);
ALTER TABLE Store ADD CONSTRAINT Store_fk0 FOREIGN KEY (customer_id) REFERENCES Customer(customer_id);
ALTER TABLE Store ADD CONSTRAINT Store_fk1 FOREIGN KEY (supplier_id) REFERENCES Supplier(supplier_id);
ALTER TABLE Store ADD CONSTRAINT Store_fk2 FOREIGN KEY (product_id) REFERENCES Product(product_id);
ALTER TABLE Store ADD CONSTRAINT Store_fk3 FOREIGN KEY (location_id) REFERENCES Location(Location_id);
I have the following OLAP query which I wrote which I don't see different from a Data mining query. Also can I be guided on how to write more complex queries for the following:
SELECT CUSTOMER.CUSTOMER_NAME,PRODUCT.PRODUCT_NAME,SALE FROM STORE INNER JOIN CUSTOMER ON STORE.CUSTOMER_ID = CUSTOMER.CUSTOMER_ID INNER JOIN PRODUCT ON STORE.PRODUCT_ID = PRODUCT.PRODUCT_ID WHERE STORE.SALE = (SELECT MAX(SALE) FROM STORE);
I will appreciate any help.
This question is too vague to have a good answer. Please refer to Oracle Data Mining for more info about Data Mining.
Data Mining start from a simple query like:
BEGIN
DBMS_PREDICTIVE_ANALYTICS.EXPLAIN(
data_table_name => 'mining_data_build_v',
explain_column_name => 'affinity_card',
result_table_name => 'ai_explain_output');
END;
/
And the skies are the limit...

ORA-02291 parent key not found, first

My first programming program is an Oracle Database graduate certificate program, and the textbook is not Oracle friendly in some places (it is a generic database textbook). I had to rewrite the CREATE table commands and what I came up with is written below.
The tables are created in my database, and I can insert values into the vendor table; however, every time I insert values into the product table I receive the ORA-02291 integrity error.
I realize that the parent key is not being found in the vendor table, but I am at a loss as to why. I have tried a combination of column and table constraints on both tables, and nothing works. If someone could help me set up this relationship so I can practice that would be great!
CREATE TABLE VENDOR(
V_CODE INTEGER NOT NULL CONSTRAINT VENDOR_P_K PRIMARY KEY,
V_NAME VARCHAR(35) NOT NULL,
V_CONTACT VARCHAR(25) NOT NULL,
V_AREACODE CHAR(3) NOT NULL,
V_PHONE CHAR(8) NOT NULL,
V_STATE CHAR(2) NOT NULL,
V_ORDER CHAR(1) NOT NULL
);
----------------------------------------------------------------------------
CREATE TABLE PRODUCT(
P_CODE VARCHAR2(10) CONSTRAINT PRODUCT_P_CODE_PK PRIMARY KEY,
P_DESCRIPT VARCHAR2(35) NOT NULL,
P_INDATE DATE NOT NULL,
P_QOH NUMBER NOT NULL,
P_MIN NUMBER NOT NULL,
P_PRICE NUMBER(8,2) NOT NULL,
P_DISCOUNT NUMBER(5,2) NOT NULL,
V_CODE INTEGER NOT NULL,
CONSTRAINT V_CODE_FK FOREIGN KEY (V_CODE) REFERENCES VENDOR (V_CODE)
);
EDIT
INSERT INTO VENDOR 2
VALUES (21225, 'Bryson, Inc.', 'Smithson', '615','223-3234','TN','Y');
INSERT INTO VENDOR 2
VALUES (21226,'Superloo, Inc.','Flushing','904','215-8995','FL','N');
INSERT INTO PRODUCT 2
VALUES ('11QER/31','Power painter, 15 psi., 3-nozzle','03-Nov-13',8,5,109.99,0.00,25595);
The relationship is set up correctly.
You can only insert foreign key values matching a primary key value in the master table. In your example, you are inserting a product with V_CODE = 25595 but you are never inserting a vendor with this V_CODE.
Maybe you intended to insert the vendor later. This does not work, as the database is enforcing the constraints for every command. Therefore, insert the vendor first and append his products later.
If you want to delete vendors, first delete its products, then delete the vendor unless you are using Foreign Keys with Cascade Delete.

Simple SQL issues, cannot figure out what I'm doing wrong to get these errors - ORA-00942 / 907 / 922

This is a supposed to be a simple SQL project, but I'm stuck on the first step. I've never worked with SQL before, so I'm pretty lost. Can someone please tell me what I did wrong that's causing these errors?
Here is the file:
SPOOL output.log;
DROP TABLE rental CASCADE CONSTRAINTS;
DROP TABLE movie CASCADE CONSTRAINTS;
DROP TABLE customer CASCADE CONSTRAINTS;
DROP TABLE distributor CASCADE CONSTRAINTS;
DROP TABLE rental_store CASCADE CONSTRAINTS;
CREATE TABLE rental (
inventory_id CHAR(10) PRIMARY KEY,
transaction_id CHAR(10) NOT NULL UNIQUE,
late DECIMAL(6,2),
damaged DECIMAL(6,2),
fail_rewind DECIMAL(6,2),
taxes DECIMAL(6,2) NOT NULL,
discount DECIMAL(6,2),
customer_id CHAR(10) NOT NULL UNIQUE,
CONTRAINT rental_FK FOREIGN KEY (customer_id) REFERENCES customer (customer_id));
CREATE TABLE movie (
title_id_number CHAR(10) PRIMARY KEY,
genre VARCHAR2(20) NOT NULL,
actor VARCHAR2(30) NOT NULL,
director VARCHAR2(30) NOT NULL,
awards VARCHAR2(30),
running_length INTEGER NOT NULL,
rating VARCHAR2(5) NOT NULL,
year_released INTEGER NOT NULL,
media_type CHAR(5) NOT NULL,
inventory_id CHAR(10) NOT NULL UNIQUE,
title VARCHAR2(30) NOT NULL,
distrib_serial INTEGER NOT NULL UNIQUE,
cat_mov_id CHAR(10) NOT NULL UNIQUE));
CREATE TABLE customer (
customer_id CHAR(10) PRIMARY KEY,
name VARCHAR2(30) NOT NULL,
address VARCHAR2(50) NOT NULL,
tele_number CHAR(10) NOT NULL UNIQUE,
rent_history INTEGER NOT NULL));
CREATE TABLE distributor (
distributor_name VARCHAR2(30) PRIMARY KEY,
catalog VARCHAR2(30) NOT NULL,
genres_offered VARCHAR2(50) NOT NULL));
CREATE TABLE rental_store (
store_name VARCHAR2(30) PRIMARY KEY,
address VARCHAR2(50) NOT NULL,
owner VARCHAR2(30) NOT NULL));
SPOOL OFF;
The errors for the DROP statements are to be expected because the tables do not yet exist. You can safely ignore them.
Most of your problems come from the second closing parenthesis, e.g.
CREATE TABLE movie (
...
cat_mov_id CHAR(10) NOT NULL UNIQUE));
^ ---- here
You need to remove them. It is only needed in the first statement because of the column list of the foreign key.
The first (real) error you get is because you misspelled CONSTRAINT (you wrote CONTRAINT. The full clause needs to be
CONSTRAINT rental_FK FOREIGN KEY (customer_id) REFERENCES customer (customer_id)
^ -- the "s" was missing here
However you can't create a foreign key constraint to a table that does not exist. So you need to change the order of the create statements to first create the customer table, then you can create the rental table.
Putting all that together, your script should look like this:
DROP TABLE rental CASCADE CONSTRAINTS;
DROP TABLE movie CASCADE CONSTRAINTS;
DROP TABLE customer CASCADE CONSTRAINTS;
DROP TABLE distributor CASCADE CONSTRAINTS;
DROP TABLE rental_store CASCADE CONSTRAINTS;
CREATE TABLE customer (
customer_id CHAR(10) PRIMARY KEY,
name VARCHAR2(30) NOT NULL,
address VARCHAR2(50) NOT NULL,
tele_number CHAR(10) NOT NULL UNIQUE,
rent_history INTEGER NOT NULL
);
CREATE TABLE rental (
inventory_id CHAR(10) PRIMARY KEY,
transaction_id CHAR(10) NOT NULL UNIQUE,
late DECIMAL(6,2),
damaged DECIMAL(6,2),
fail_rewind DECIMAL(6,2),
taxes DECIMAL(6,2) NOT NULL,
discount DECIMAL(6,2),
customer_id CHAR(10) NOT NULL UNIQUE,
CONSTRAINT rental_FK FOREIGN KEY (customer_id) REFERENCES customer (customer_id)
);
CREATE TABLE movie (
title_id_number CHAR(10) PRIMARY KEY,
genre VARCHAR2(20) NOT NULL,
actor VARCHAR2(30) NOT NULL,
director VARCHAR2(30) NOT NULL,
awards VARCHAR2(30),
running_length INTEGER NOT NULL,
rating VARCHAR2(5) NOT NULL,
year_released INTEGER NOT NULL,
media_type CHAR(5) NOT NULL,
inventory_id CHAR(10) NOT NULL UNIQUE,
title VARCHAR2(30) NOT NULL,
distrib_serial INTEGER NOT NULL UNIQUE,
cat_mov_id CHAR(10) NOT NULL UNIQUE
);
CREATE TABLE distributor (
distributor_name VARCHAR2(30) PRIMARY KEY,
catalog VARCHAR2(30) NOT NULL,
genres_offered VARCHAR2(50) NOT NULL
);
CREATE TABLE rental_store (
store_name VARCHAR2(30) PRIMARY KEY,
address VARCHAR2(50) NOT NULL,
owner VARCHAR2(30) NOT NULL
);
Unrelated, but: you do not want to use the CHAR data type. It's more efficient and will give you less headaches if you use VARCHAR for every character column.
Of course the first time you run the script your DROP TABLEs will fail because you haven't created them yet. That's to be expected and is acceptable in such a script.
Beyond that, if you are going to create FK relationships, you need to create the parent table before you create the child, which you will see after you correct your misspelled key word.
I will leave it as an exercise for the student to take that clue and locate the mis-spelled key word in the first CREATE TABLE statement.

SQL Error 02291 - Issues with foreign keys [duplicate]

This question already has answers here:
SQL Error: ORA-02291: integrity constraint
(4 answers)
Closed 7 years ago.
We are trying to insert data to our tables, however we have run into an error and can't see the problem. This is what we are getting -
INSERT INTO Item(Manifest_barcode,Trip_ID,Item_weight,Pickup_customer,Delivery_customer,Category) VALUES (159601450,73495,2156,166,184,'A')
Error report -
SQL Error: ORA-02291: integrity constraint (HR.SYS_C009055) violated - parent key not found
02291. 00000 - "integrity constraint (%s.%s) violated - parent key not found"
We have checked the order of the creation of the tables, and as far as we can tell everything is in the right place. All of the foreign keys seem to be correct as well.
This is how we are dropping/creating the tables -
DROP TABLE Item;
DROP TABLE Trip;
DROP TABLE Vehicle;
DROP TABLE Vehicle_Type;
DROP TABLE Employee;
DROP TABLE Customer;
DROP TABLE Category;
CREATE TABLE Category(
Category VARCHAR2(100) NOT NULL,
Description VARCHAR2(100) NOT NULL,
Requirements VARCHAR2(100),
PRIMARY KEY(Category)
);
CREATE TABLE Customer(
Reference INT NOT NULL,
Name VARCHAR2(100) NOT NULL,
Address VARCHAR2(100) NOT NULL,
Town VARCHAR2(100) NOT NULL,
Post_code VARCHAR2(8) NOT NULL,
Telephone INT NOT NULL,
Contact_first_name VARCHAR2(100) NOT NULL,
Contact_last_name VARCHAR2(100) NOT NULL,
Email VARCHAR2(100) NOT NULL,
PRIMARY KEY(Reference)
);
CREATE TABLE Employee(
Employee_no INT NOT NULL,
First_name VARCHAR2(100) NOT NULL,
Last_name VARCHAR2(100) NOT NULL,
NI_No VARCHAR2(100) NOT NULL,
Telephone VARCHAR2(100) NOT NULL,
Mobile VARCHAR2(100) NOT NULL,
Hazardous_goods VARCHAR2(100) NOT NULL,
PRIMARY KEY(Employee_no)
);
CREATE TABLE Vehicle_Type(
Vehicle_Type_ID VARCHAR2(100) NOT NULL,
Model VARCHAR2(100) NOT NULL,
Make VARCHAR2(100) NOT NULL,
PRIMARY KEY(Vehicle_Type_ID)
);
CREATE TABLE Vehicle(
Registration VARCHAR2(100) NOT NULL,
Vehicle_Type_ID VARCHAR2(100) NOT NULL,
GVW VARCHAR2(100) NOT NULL,
Vehicle_Year INT NOT NULL,
Body VARCHAR2(100),
PRIMARY KEY(Registration),
FOREIGN KEY(Vehicle_Type_ID) REFERENCES Vehicle_Type(Vehicle_Type_ID)
);
CREATE TABLE Trip(
Trip_ID INT NOT NULL,
Departure_date VARCHAR2(100) NOT NULL,
Return_date VARCHAR2(100) NOT NULL,
Employee_no INT NOT NULL,
Vehicle_registration VARCHAR2(100) NOT NULL,
PRIMARY KEY(Trip_ID),
FOREIGN KEY(Employee_no) REFERENCES Employee(Employee_no)
);
CREATE TABLE Item(
Manifest_barcode VARCHAR2(100) NOT NULL,
Trip_ID INT NOT NULL,
Item_weight INT NOT NULL,
Pickup_customer INT NOT NULL,
Delivery_customer INT NOT NULL,
Category VARCHAR2(100) NOT NULL,
PRIMARY KEY(Manifest_barcode),
FOREIGN KEY(Trip_ID) REFERENCES Trip(Trip_ID),
FOREIGN KEY(Category) REFERENCES Category(Category)
);
This is how the items are being inserted -
INSERT INTO Customer (Name,Reference,Address,Town,Post_code,Telephone,Contact_first_name,Contact_last_name,Email) VALUES
('Calash Ltd.',1,'88 Rinkomania Lane','Cardigan','SA55 8BA',11671595763,'Cameron','Dunnico','c.dunnico#calash.co.uk');
INSERT INTO Employee (Employee_no,First_name,Last_name,NI_No,Telephone,Mobile,Hazardous_goods) VALUES
(0045619,'Eamon','O''Looney','JJ 56 53 26 B','1656727840','76599770175','N');
INSERT INTO Vehicle_Type (Vehicle_Type_ID,Model,Make) VALUES
(1,'RIEVER','ALBION');
INSERT INTO Vehicle(Registration,Vehicle_Type_ID,GVW,Vehicle_Year,Body) VALUES
('4585 AW',1,20321,1963,'');
INSERT INTO Category (Category, Description, Requirements) VALUES
('A','Normal','');
INSERT INTO Trip(Trip_ID,Departure_date,Return_date,Employee_no,Vehicle_registration) VALUES
(72943,'40910','40914',0028539,'BR58BXE');
INSERT INTO Item(Manifest_barcode,Trip_ID,Item_weight,Pickup_customer,Delivery_customer,Category) VALUES
(541769754,73421,3629,44,145,'A');
Anyone have any suggestions?
Your full insert script has 13 inserts into the item table with trip_id 73495. Your error is being thrown from the first one:
INSERT INTO Item(Manifest_barcode,Trip_ID,Item_weight,Pickup_customer,Delivery_customer,Category)
VALUES (159601450,73495,2156,166,184,'A');
Your script does not have a matching insert for the trip table. You have IDs either side:
INSERT INTO Trip(Trip_ID,Departure_date,Return_date,Employee_no,Vehicle_registration)
VALUES (73494,'40994','40995',0077517,'PY11 OAA');
INSERT INTO Trip(Trip_ID,Departure_date,Return_date,Employee_no,Vehicle_registration)
VALUES (73496,'40994','41000',0083413,'PY58 UHF');
But there is not one for ID 73495.
Searching that script for 73495 only matches those 13 item inserts, and a later item which has a manifest_barcode of 617349505 which contains it. But that is all.
There is no matching trip, which is what the exception is telling you.
Hi please check the following
you have inserted this row in the employee table with employee_no=0045619
INSERT INTO Employee (Employee_no,First_name,Last_name,NI_No,Telephone,Mobile,Hazardous_goods) VALUES
(0045619,'Eamon','O''Looney','JJ 56 53 26 B','1656727840','76599770175','N');
trip is the table which was referencing the employee table
INSERT INTO Trip(Trip_ID,Departure_date,Return_date,Employee_no,Vehicle_registration) VALUES
(72943,'40910','40914',0028539,'BR58BXE');
in this insert statement you had inserted a row with employee_no=0028539, which was not matched with the employee_no(0045619) available in the employee table.
please correct the value and try to insert with the same employee number in the employee table
---------editied----------------
check the tripid in item(73421) is available in the trip table?