In: Computer Science
SPOOL output.log
DROP TABLE Customers CASCADE CONSTRAINT;
DROP TABLE Orders CASCADE CONSTRAINT;
DROP TABLE Products CASCADE CONSTRAINT;
DROP TABLE Distributors CASCADE CONSTRAINT;
DROP TABLE Catalogs CASCADE CONSTRAINT;
DROP TABLE Rentals CASCADE CONSTRAINT;
CREATE TABLE Customers (
Customer_id NUMBER(10) NOT NULL,
CustomerFirst_name VARCHAR(20) NOT NULL,
CustomerLast_name VARCHAR(20) NOT NULL,
CustomerStreet_address VARCHAR(30) NOT NULL,
CostumerCity VARCHAR(20) NOT NULL,
CustomerState CHAR(2) NOT NULL,
CostumerZip VARCHAR(9) NOT NULL,
CustomerPhone_number VARCHAR(12) NOT NULL,
CONSTRAINT Customer_PK PRIMARY KEY (Customer_id));
--Customers
INSERT INTO Customers (Customer_id, CustomerFirst_name,
CustomerLast_name, CustomerStreet_address, CostumerCity,
CustomerState,
CostumerZip, CustomerPhone_number) VALUES ('100', 'Ben', 'Bill',
'201 Ash Street', 'San Silva', 'MD', '20850',
'443-123-4567');
INSERT INTO Customers (Customer_id, CustomerFirst_name,
CustomerLast_name, CustomerStreet_address, CostumerCity,
CustomerState, CostumerZip,
CustomerPhone_number) VALUES ('101', 'James', 'Seth', '142 Athens
Avenue', 'Silver Boro', 'MD', '20841', '443-230-4444');
INSERT INTO Customers (Customer_id, CustomerFirst_name,
CustomerLast_name, CustomerStreet_address, CostumerCity,
CustomerState,
CostumerZip, CustomerPhone_number) VALUES ('200', 'Victor',
'Jones', '124 Flower Street', 'Rockville','MD', '20857',
'301-547-2036');
INSERT INTO Customers (Customer_id, CustomerFirst_name,
CustomerLast_name, CustomerStreet_address, CostumerCity,
CustomerState, CostumerZip,
CustomerPhone_number) VALUES ('300', 'Ashley', 'Maverick', '105
University Boulevard', 'Baltimore', 'MD', '21593',
'228-567-8174');
INSERT INTO Customers (Customer_id, CustomerFirst_name,
CustomerLast_name, CustomerStreet_address, CostumerCity,
CustomerState, CostumerZip,
CustomerPhone_number) VALUES ('450', 'Bill','Booker', '208 New
Hampshire Avenue', 'Wheaton', 'MD', '20103', '250-413-7020');
CREATE TABLE Orders(
Order_id NUMBER(10) NOT NULL,
OrderDate DATE DEFAULT SYSDATE,
CONSTRAINT Order_PK PRIMARY KEY (Order_id));
-- Order
INSERT INTO Orders (Order_id, OrderDate) VALUES ('1',
TO_DATE('02/05/2007','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate) VALUES ('2',
TO_DATE('2/20/2011','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate) VALUES ('3',
TO_DATE('02/05/2003','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate) VALUES ('4',
TO_DATE('02/05/2005','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('5',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('6',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('7',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('8',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('9',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('10',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('11',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('12',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('13',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('14',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('15',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('15',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('16',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('17',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('18',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('19',
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES ('20',
TO_DATE('02/05/2006','MM/DD/YYYY'));
CREATE TABLE Products (
Product_id NUMBER(10) NOT NULL CONSTRAINT Product_PK PRIMARY
KEY,
ProductDescription VARCHAR2(50),
ProductMovieType varchar(11),
Order_id NUMBER(10) NOT NULL
CONSTRAINT Product_FK REFERENCES Orders (Order_id));
-- Product
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('1', 'Beauty and the Beast',
'Romance','6');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('2', 'Mist',
'Thriller','7');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('3', 'Police Academy',
'Comedy','8');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('5', 'When Sally met Harry',
'Romance','9');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('6', 'Rambo',
'Action','10');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('7', 'Rambo',
'Action','10');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('8', 'Rambo',
'Action','10');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('9', 'Rambo',
'Action','10');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('10', 'Rambo',
'Action','10');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('11', 'Rambo',
'Action','10');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('12', 'Beauty and the Beast',
'Romance','6');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('13', 'Mist',
'Thriller','7');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('14', 'Police Academy',
'Comedy','8');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('15', 'When Sally met Harry',
'Romance','9');
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('16', 'Rambo',
'Action','10');
CREATE TABLE Distributors (
DistributorDisc_id NUMBER(11,0) NOT NULL,
DistributorPrice NUMBER(11,0) NOT NULL,
DistributorOrderQuantity NUMBER(11),
Order_id NUMBER(10) NOT NULL,
CONSTRAINT Distributor_PK PRIMARY KEY (DistributorDisc_id) ,
CONSTRAINT Distributor_FK FOREIGN KEY (Order_id) REFERENCES Orders
(Order_id));
-- Distributor
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('1', '5','10',
'11');
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('2', '5','10',
'12');
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('3',
'15','10','13');
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('4', '5','10',
'14');
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('5', '5','10',
'15');
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('6', '5','10',
'15');
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('7', '5','10',
'15');
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('8', '5','10',
'15');
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('9', '5','10',
'15');
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('10', '5','10',
'15');
CREATE TABLE Catalogs (
Catalog_id NUMBER(5,0) NOT NULL,
CatalogRating VARCHAR(10) NOT NULL,
CatalogAcademyAwards VARCHAR(50) NOT NULL,
CatalogDateReleased DATE DEFAULT SYSDATE,
Product_id NUMBER(10) NOT NULL,
Order_id NUMBER(10) NOT NULL,
DistributorDisc_id NUMBER(11,0) NOT NULL,
CONSTRAINT Catalog_PK1 PRIMARY KEY (Catalog_id),
CONSTRAINT Catalog_FK1 FOREIGN KEY (Order_id) REFERENCES Orders
(Order_id),
CONSTRAINT Catalog_FK2 FOREIGN KEY (Product_id) REFERENCES Products
(Product_id),
CONSTRAINT Catalog_FK3 FOREIGN KEY (DistributorDisc_id) REFERENCES
Distributors (DistributorDisc_id));
-- Catalog
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
VALUES ('1', 'Rated
R','2',TO_DATE('02/05/2000','MM/DD/YYYY'),'7','16','6');
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
VALUES ('2', 'Parental Guide', '12',
TO_DATE('02/05/2001','MM/DD/YYYY'),'8','17','7');
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
VALUES ('3', 'Youth','3',TO_DATE('02/05/2002','MM/DD/YYYY'),
'9','18','8');
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
VALUES ('4', 'Everyone','8',
TO_DATE('02/05/2003','MM/DD/YYYY'),'10','19','9');
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
VALUES ('5',
'Preschool','9',TO_DATE('02/05/2004','MM/DD/YYYY'),'11','20','10');
CREATE TABLE Rentals(
Rental_id NUMBER(9) NOT NULL,
RentalReturnDate DATE DEFAULT SYSDATE,
RentalRentedQuantity VARCHAR(2) NOT NULL,
RentalTotal_charge NUMBER(19,4) NOT NULL,
RentalTax NUMBER(19,4) NOT NULL,
Product_id NUMBER(10) NOT NULL,
CONSTRAINT Rental_PK PRIMARY KEY(Rental_id),
CONSTRAINT Rental_FK FOREIGN KEY(Product_id) REFERENCES
Products(Product_id));
-- Rental
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
VALUES ('1', TO_DATE('04/05/2009','MM/DD/YYYY'), '35','17.99',
'0.3','11');
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
VALUES ('2', TO_DATE('03/04/2001','MM/DD/YYYY'), '34','17.99',
'0.3','12');
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
VALUES ('3', TO_DATE('04/03/2002','MM/DD/YYYY'), '33','17.99',
'0.3','13');
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
VALUES ('4', TO_DATE('04/01/2003','MM/DD/YYYY'), '32','17.99',
'0.3','14');
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
VALUES ('5', TO_DATE('04/03/2004','MM/DD/YYYY'), '31','17.99',
'0.3','15');
SPOOL OFF;
Error message
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('1', 'Beauty and the Beast',
'Romance','6')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('2', 'Mist',
'Thriller','7')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('3', 'Police Academy',
'Comedy','8')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('5', 'When Sally met Harry',
'Romance','9')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('6', 'Rambo',
'Action','10')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('7', 'Rambo',
'Action','10')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('8', 'Rambo',
'Action','10')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('9', 'Rambo',
'Action','10')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('10', 'Rambo',
'Action','10')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('11', 'Rambo',
'Action','10')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('12', 'Beauty and the Beast',
'Romance','6')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('13', 'Mist',
'Thriller','7')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('14', 'Police Academy',
'Comedy','8')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('15', 'When Sally met Harry',
'Romance','9')
*
ERROR at line 1:
ORA-01722: invalid number
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('16', 'Rambo',
'Action','10')
*
ERROR at line 1:
ORA-01722: invalid number
CREATE TABLE Distributors (
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('1', '5','10',
'11')
*
ERROR at line 1:
ORA-00001: unique constraint (CM320P17.DISTRIBUTOR_PK) violated
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('2', '5','10',
'12')
*
ERROR at line 1:
ORA-00001: unique constraint (CM320P17.DISTRIBUTOR_PK) violated
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('3',
'15','10','13')
*
ERROR at line 1:
ORA-00001: unique constraint (CM320P17.DISTRIBUTOR_PK) violated
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('4', '5','10',
'14')
*
ERROR at line 1:
ORA-00001: unique constraint (CM320P17.DISTRIBUTOR_PK) violated
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('5', '5','10',
'15')
*
ERROR at line 1:
ORA-00001: unique constraint (CM320P17.DISTRIBUTOR_PK) violated
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('6', '5','10',
'15')
*
ERROR at line 1:
ORA-00001: unique constraint (CM320P17.DISTRIBUTOR_PK) violated
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('7', '5','10',
'15')
*
ERROR at line 1:
ORA-00001: unique constraint (CM320P17.DISTRIBUTOR_PK) violated
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('8', '5','10',
'15')
*
ERROR at line 1:
ORA-00001: unique constraint (CM320P17.DISTRIBUTOR_PK) violated
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('9', '5','10',
'15')
*
ERROR at line 1:
ORA-00001: unique constraint (CM320P17.DISTRIBUTOR_PK) violated
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES ('10', '5','10',
'15')
*
ERROR at line 1:
ORA-00001: unique constraint (CM320P17.DISTRIBUTOR_PK) violated
CREATE TABLE Catalogs (
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
*
ERROR at line 1:
ORA-02291: integrity constraint (CM320P17.CATALOG_FK2) violated -
parent key
not found
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
*
ERROR at line 1:
ORA-02291: integrity constraint (CM320P17.CATALOG_FK2) violated -
parent key
not found
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
*
ERROR at line 1:
ORA-02291: integrity constraint (CM320P17.CATALOG_FK2) violated -
parent key
not found
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
*
ERROR at line 1:
ORA-02291: integrity constraint (CM320P17.CATALOG_FK2) violated -
parent key
not found
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
*
ERROR at line 1:
ORA-02291: integrity constraint (CM320P17.CATALOG_FK2) violated -
parent key
not found
CREATE TABLE Rentals(
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
*
ERROR at line 1:
ORA-02291: integrity constraint (CM320P17.RENTAL_FK) violated -
parent key not
found
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
*
ERROR at line 1:
ORA-02291: integrity constraint (CM320P17.RENTAL_FK) violated -
parent key not
found
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
*
ERROR at line 1:
ORA-02291: integrity constraint (CM320P17.RENTAL_FK) violated -
parent key not
found
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
*
ERROR at line 1:
ORA-02291: integrity constraint (CM320P17.RENTAL_FK) violated -
parent key not
found
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
*
ERROR at line 1:
ORA-02291: integrity constraint (CM320P17.RENTAL_FK) violated -
parent key not
found
There are errors shown in your question. I assume your question
is to resolve those errors.
Here are the ways you get ride of those errors. You have the erros
nos. ORA-00955, ORA-01722, ORA-00001 and ORA-02291. Explainations
are given below as to why you get these errors and how to get rid
of them. Please do rate the answer if you find it helped you.
=====================================================
1.Error ORA-00955: name is already used by an existing object
This error occurs when that table is already existing and you are issuing a create table with the same table name. So either you want to retain the existing table, or you want to re-create it fresh, after using the drop table statement. So if you want to drop all tables and then recreate, use these statements below. Remember, if a table does not exist and you try to drop it , you might see a error message. You can drop a table only if its already created. So a simple way to see if it exists is give a select statement like select * from <table_name> and see if you get any results or error.
DROP TABLE Customers CASCADE CONSTRAINT;
DROP TABLE Orders CASCADE CONSTRAINT;
DROP TABLE Products CASCADE CONSTRAINT;
DROP TABLE Distributors CASCADE CONSTRAINT;
DROP TABLE Catalogs CASCADE CONSTRAINT;
DROP TABLE Rentals CASCADE CONSTRAINT;
2. ORA-01722: invalid number
You get this error when you have declared a field in table as a number where as you are inserting someother type for example a string value into it. In error messages given by you, lets take an example
INSERT INTO Products (Product_id, ProductDescription, ProductMovieType, Order_id) VALUES ('1', 'Beauty and the Beast', 'Romance','6')
While creating the table, both product_id and order_id are defined
to be numbers where as in the insert statement, those values are
being entered as strings using single quotes. Numberic values
should always be given without quotes. So both product_id and
order_id values should be given without quotes as shown
below.
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (1, 'Beauty and the Beast',
'Romance',6)
So all insert statements in your question, need to be changed to
enter numeric values without quotes to get rid of the Error
ORA-01722
3. Error ORA-00001:unique constraint ... violated
This error is caused when you insert a new row with a primary key
which already is in the table. In your question,
ERROR at line 1:
ORA-00001: unique constraint (CM320P17.DISTRIBUTOR_PK) violated
This error occurs because you are trying to enter the row with
primary key which already is existing in the table. If you notice
carefully, you see an error
ORA-00955: name is already used by an existing object
before primary key violation.
i.e. Distributor table already exists and you tried to recreate it. Since it already exists it should be having data in it. And so your new insert statements violate the primary key constraint because of duplicate.
So either you want to drop the table, recreate it and then use the insert statement or insert a new row with new primary key value for DistributorDisc_id
4.Error ORA-02291 integrity constraint (...<foreign key
name>) violated - parent key not found
This error occurs when you insert a row in a table with a foreign key value that tries to find a matching primary key row but is unable to find a matching row in the primary table. For example,
From your question,you get error on
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
VALUES ('1', 'Rated
R','2',TO_DATE('02/05/2000','MM/DD/YYYY'),'7','16','6');
The error is
ERROR at line 1:
ORA-02291: integrity constraint (CM320P17.CATALOG_FK2) violated -
parent key
not found
This error is given because the foreign key CM320P17.CATALOG_FK2 i.e Product_id is trying to look up for matching value 7 in the products table but didnt find it. Can you guess why it didn't find it ? The reason is that the insertion of the all product rows failed previously because you inserted those numeric values as strings as explained above. So you will need to fix those errors by inserting numeric values without quotes and also for rows in catalog table you need to give numeric values without quotes. So the above insert statement would look like
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
VALUES (1, 'Rated
R','2',TO_DATE('02/05/2000','MM/DD/YYYY'),7,16,6);
You see similar errors on Rentals table as well.
So I am re-writing the all your statements removing quotes for
numeric values. Also if you already have the tables in the DB,
please drop them using drop table and then recreate them using
create table. Also changed RentalQuantity in Rentals table from
VARCHAR to NUMBER type since quantity should be numeric
value.
===================================================
DROP TABLE Customers CASCADE CONSTRAINT;
DROP TABLE Orders CASCADE CONSTRAINT;
DROP TABLE Products CASCADE CONSTRAINT;
DROP TABLE Distributors CASCADE CONSTRAINT;
DROP TABLE Catalogs CASCADE CONSTRAINT;
DROP TABLE Rentals CASCADE CONSTRAINT;
CREATE TABLE Customers (
Customer_id NUMBER(10) NOT NULL,
CustomerFirst_name VARCHAR(20) NOT NULL,
CustomerLast_name VARCHAR(20) NOT NULL,
CustomerStreet_address VARCHAR(30) NOT NULL,
CostumerCity VARCHAR(20) NOT NULL,
CustomerState CHAR(2) NOT NULL,
CostumerZip VARCHAR(9) NOT NULL,
CustomerPhone_number VARCHAR(12) NOT NULL,
CONSTRAINT Customer_PK PRIMARY KEY (Customer_id));
INSERT INTO Customers (Customer_id, CustomerFirst_name,
CustomerLast_name, CustomerStreet_address, CostumerCity,
CustomerState,
CostumerZip, CustomerPhone_number) VALUES (100, 'Ben', 'Bill', '201
Ash Street', 'San Silva', 'MD', '20850', '443-123-4567');
INSERT INTO Customers (Customer_id, CustomerFirst_name,
CustomerLast_name, CustomerStreet_address, CostumerCity,
CustomerState, CostumerZip,
CustomerPhone_number) VALUES (101, 'James', 'Seth', '142 Athens
Avenue', 'Silver Boro', 'MD', '20841', '443-230-4444');
INSERT INTO Customers (Customer_id, CustomerFirst_name,
CustomerLast_name, CustomerStreet_address, CostumerCity,
CustomerState,
CostumerZip, CustomerPhone_number) VALUES (200, 'Victor', 'Jones',
'124 Flower Street', 'Rockville','MD', '20857',
'301-547-2036');
INSERT INTO Customers (Customer_id, CustomerFirst_name,
CustomerLast_name, CustomerStreet_address, CostumerCity,
CustomerState, CostumerZip,
CustomerPhone_number) VALUES (300, 'Ashley', 'Maverick', '105
University Boulevard', 'Baltimore', 'MD', '21593',
'228-567-8174');
INSERT INTO Customers (Customer_id, CustomerFirst_name,
CustomerLast_name, CustomerStreet_address, CostumerCity,
CustomerState, CostumerZip,
CustomerPhone_number) VALUES (450, 'Bill','Booker', '208 New
Hampshire Avenue', 'Wheaton', 'MD', '20103', '250-413-7020');
CREATE TABLE Orders(
Order_id NUMBER(10) NOT NULL,
OrderDate DATE DEFAULT SYSDATE,
CONSTRAINT Order_PK PRIMARY KEY (Order_id));
INSERT INTO Orders (Order_id, OrderDate) VALUES (1,
TO_DATE('02/05/2007','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate) VALUES (2,
TO_DATE('2/20/2011','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate) VALUES (3,
TO_DATE('02/05/2003','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate) VALUES (4,
TO_DATE('02/05/2005','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (5,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (6,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (7,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (8,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (9,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (10,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (11,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (12,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (13,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (14,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (15,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (16,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (17,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (18,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (19,
TO_DATE('02/05/2006','MM/DD/YYYY'));
INSERT INTO Orders (Order_id, OrderDate)VALUES (20,
TO_DATE('02/05/2006','MM/DD/YYYY'));
CREATE TABLE Products (
Product_id NUMBER(10) NOT NULL CONSTRAINT Product_PK PRIMARY
KEY,
ProductDescription VARCHAR2(50),
ProductMovieType varchar(11),
Order_id NUMBER(10) NOT NULL
CONSTRAINT Product_FK REFERENCES Orders (Order_id));
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (1, 'Beauty and the Beast',
'Romance',6);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (2, 'Mist', 'Thriller',7);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (3, 'Police Academy',
'Comedy',8);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (5, 'When Sally met Harry',
'Romance',9);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (6, 'Rambo', 'Action',10);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (7, 'Rambo', 'Action',10);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (8, 'Rambo', 'Action',10);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (9, 'Rambo', 'Action',10);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES ('10', 'Rambo',
'Action',10);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (11, 'Rambo',
'Action',10);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (12, 'Beauty and the Beast',
'Romance',6);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (13, 'Mist',
'Thriller',7);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (14, 'Police Academy',
'Comedy',8);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (15, 'When Sally met Harry',
'Romance',9);
INSERT INTO Products (Product_id, ProductDescription,
ProductMovieType, Order_id) VALUES (16, 'Rambo', 'Action',10);
CREATE TABLE Distributors (
DistributorDisc_id NUMBER(11,0) NOT NULL,
DistributorPrice NUMBER(11,0) NOT NULL,
DistributorOrderQuantity NUMBER(11),
Order_id NUMBER(10) NOT NULL,
CONSTRAINT Distributor_PK PRIMARY KEY (DistributorDisc_id) ,
CONSTRAINT Distributor_FK FOREIGN KEY (Order_id) REFERENCES Orders
(Order_id));
-- Distributor
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES (1, '5','10', 11);
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES (2, '5','10', 12);
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES (3, '15','10',13);
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES (4, '5','10', 14);
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES (5, '5','10', 15);
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES (6, '5','10', 15);
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES (7, '5','10', 15);
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES (8, '5','10', 15);
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES (9, '5','10', 15);
INSERT INTO Distributors (DistributorDisc_id, DistributorPrice,
DistributorOrderQuantity, Order_id) VALUES (10, '5','10', 15);
CREATE TABLE Catalogs (
Catalog_id NUMBER(5,0) NOT NULL,
CatalogRating VARCHAR(10) NOT NULL,
CatalogAcademyAwards VARCHAR(50) NOT NULL,
CatalogDateReleased DATE DEFAULT SYSDATE,
Product_id NUMBER(10) NOT NULL,
Order_id NUMBER(10) NOT NULL,
DistributorDisc_id NUMBER(11,0) NOT NULL,
CONSTRAINT Catalog_PK1 PRIMARY KEY (Catalog_id),
CONSTRAINT Catalog_FK1 FOREIGN KEY (Order_id) REFERENCES Orders
(Order_id),
CONSTRAINT Catalog_FK2 FOREIGN KEY (Product_id) REFERENCES Products
(Product_id),
CONSTRAINT Catalog_FK3 FOREIGN KEY (DistributorDisc_id) REFERENCES
Distributors (DistributorDisc_id));
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
VALUES (1, 'Rated
R','2',TO_DATE('02/05/2000','MM/DD/YYYY'),7,16,6);
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
VALUES (2, 'Parental Guide', '12',
TO_DATE('02/05/2001','MM/DD/YYYY'),8,17,7);
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
VALUES (3, 'Youth','3',TO_DATE('02/05/2002','MM/DD/YYYY'),
9,18,8);
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
VALUES (4, 'Everyone','8',
TO_DATE('02/05/2003','MM/DD/YYYY'),10,19,9);
INSERT INTO Catalogs
(Catalog_id,CatalogAcademyAwards,CatalogRating,
CatalogDateReleased, Product_id, Order_id,
DistributorDisc_id)
VALUES (5,
'Preschool','9',TO_DATE('02/05/2004','MM/DD/YYYY'),11,20,10);
CREATE TABLE Rentals(
Rental_id NUMBER(9) NOT NULL,
RentalReturnDate DATE DEFAULT SYSDATE,
RentalRentedQuantity NUMBER(2) NOT NULL,
RentalTotal_charge NUMBER(19,4) NOT NULL,
RentalTax NUMBER(19,4) NOT NULL,
Product_id NUMBER(10) NOT NULL,
CONSTRAINT Rental_PK PRIMARY KEY(Rental_id),
CONSTRAINT Rental_FK FOREIGN KEY(Product_id) REFERENCES
Products(Product_id));
-- Rental
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
VALUES (1, TO_DATE('04/05/2009','MM/DD/YYYY'), 35,17.99,
0.3,11);
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
VALUES (2, TO_DATE('03/04/2001','MM/DD/YYYY'), 34,17.99,
0.3,12);
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
VALUES (3, TO_DATE('04/03/2002','MM/DD/YYYY'), 33,17.99,
0.3,13);
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
VALUES (4, TO_DATE('04/01/2003','MM/DD/YYYY'), 32,17.99,
0.3,14);
INSERT INTO Rentals (Rental_id, RentalReturnDate,
RentalRentedQuantity, RentalTotal_charge, RentalTax,
Product_id)
VALUES (5, TO_DATE('04/03/2004','MM/DD/YYYY'), 31,17.99,
0.3,15);
SPOOL OFF;