-- drop tables
DROP TABLE REQUEST CASCADE CONSTRAINTS;
DROP TABLE FULLORDER CASCADE CONSTRAINTS;
DROP TABLE PRODUCT CASCADE CONSTRAINTS;
DROP TABLE CUSTOMER CASCADE CONSTRAINTS;
-- create and link tables
CREATE TABLE CUSTOMER
(
CustomerID INTEGER,
Name
VARCHAR2(40),
City
VARCHAR2(20),
State CHAR(2),
Zip CHAR(5),
CONSTRAINT PK_CUSTOMER
PRIMARY KEY (CustomerID)
);
CREATE TABLE PRODUCT
(
ProductID INTEGER,
Description VARCHAR2(30),
Material VARCHAR2(20),
Price NUMBER(5,2),
CONSTRAINT PK_PRODUCT
PRIMARY KEY (ProductID)
);
CREATE TABLE FULLORDER
( OrderID INTEGER,
OrderDate DATE,
CustomerID INTEGER,
CONSTRAINT PK_FULLORDER
PRIMARY KEY (OrderID),
CONSTRAINT FK_FULLORDER_CUSTOMER
FOREIGN KEY (CustomerID)
REFERENCES
CUSTOMER(CustomerID)
);
CREATE TABLE REQUEST
(
OrderID INTEGER,
ProductID INTEGER,
Quantity INTEGER,
CONSTRAINT PK_REQUEST
PRIMARY KEY (OrderID,
ProductID),
CONSTRAINT FK_REQUEST_FULLORDER
FOREIGN KEY (OrderID)
REFERENCES FULLORDER(OrderID),
CONSTRAINT FK_REQUEST_PRODUCT
FOREIGN KEY (ProductID)
REFERENCES PRODUCT(ProductID)
);
-- populate tables
INSERT INTO CUSTOMER VALUES
(1, 'Mannys Home Style', 'Newburgh', 'NY',
'12550');
INSERT INTO CUSTOMER VALUES
(2, 'Furniture-palooza', 'Hauppauge', 'NY',
'11788');
INSERT INTO CUSTOMER VALUES
(3, 'Finer Home Furniture', 'Hartford', 'CT',
'06167');
INSERT INTO CUSTOMER VALUES
(4, 'Midwest Antique Furnishings', 'Lansing', 'MI',
'48922');
INSERT INTO CUSTOMER VALUES
(5, 'Californian Comfort', 'Irvine', 'CA',
'92612');
INSERT INTO CUSTOMER VALUES
(6, 'Unpainted Arizona', 'Sedona', 'AZ',
'87507');
INSERT INTO CUSTOMER VALUES
(7, 'Furthur Furnishings', 'San Francisco', 'CA',
'94121');
INSERT INTO CUSTOMER VALUES
(10, 'Coastal Casuals', 'Miami', 'FL', '33101');
INSERT INTO CUSTOMER VALUES
(11, 'Mountain Forest Home', 'Oregon City', 'OR',
'97045');
INSERT INTO CUSTOMER VALUES
(12, 'Classic Home', 'Albany', 'NY', '12209');
INSERT INTO CUSTOMER VALUES
(13, 'East Coast Furnishings', 'Nutley', 'NJ',
'07110');
INSERT INTO CUSTOMER VALUES
(14, 'Home Impressions', 'Fort Myers', 'FL',
'33901');
INSERT INTO CUSTOMER VALUES
(15, 'Mountain Furniture', 'Boulder', 'CO',
'80514');
INSERT INTO CUSTOMER VALUES
(16, 'Vintage Furniture', 'Ann Arbor', 'MI',
'48103');
INSERT INTO CUSTOMER VALUES
(17, 'Home Design Classics', 'Simsbury', 'CT',
'06070');
INSERT INTO CUSTOMER VALUES
(20, 'M and H Casual Furniture and Stuff', 'Seattle',
'WA', '98105');
INSERT INTO CUSTOMER VALUES
(21, 'Seminole Interiors', 'Seminole', 'FL',
'34646');
INSERT INTO PRODUCT VALUES
(101, 'Dining Table', 'Oak', 500.00);
INSERT INTO PRODUCT VALUES
(102, 'Dining Table', 'Maple', 475.00);
INSERT INTO PRODUCT VALUES
(103, 'Dining Table', 'Maple', 500.00);
INSERT INTO PRODUCT VALUES
(104, 'Dining Table', 'Oak', 250.00);
INSERT INTO PRODUCT VALUES
(105, 'Wardrobe', 'Oak', 300.00);
INSERT INTO PRODUCT VALUES
(106, 'Wardrobe', 'Pine', 375.00);
INSERT INTO PRODUCT VALUES
(107, 'Wardrobe', 'Oak', 425.00);
INSERT INTO PRODUCT VALUES
(208, 'Entertainment Center', 'Cherry', 550.00);
INSERT INTO PRODUCT VALUES
(209, 'Entertainment Center', 'Pine', 350.00);
INSERT INTO FULLORDER VALUES
(1001, DATE '2017-12-30', 10);
INSERT INTO FULLORDER VALUES
(1002, DATE '2017-12-30', 5);
INSERT INTO FULLORDER VALUES
(1003, DATE '2017-12-30', 12);
INSERT INTO FULLORDER VALUES
(1004, DATE '2018-01-15', 13);
INSERT INTO FULLORDER VALUES
(1005, DATE '2018-02-03', 20);
INSERT INTO FULLORDER VALUES
(1006, DATE '2018-02-03', 6);
INSERT INTO FULLORDER VALUES
(1007, DATE '2018-03-10', 13);
INSERT INTO FULLORDER VALUES
(1008, DATE '2018-08-01', 20);
INSERT INTO FULLORDER VALUES
(1009, DATE '2018-08-01', 13);
INSERT INTO FULLORDER VALUES
(1010, DATE '2018-09-30', 6);
INSERT INTO FULLORDER VALUES
(1011, DATE '2018-09-30', 2);
INSERT INTO FULLORDER VALUES
(1012, DATE '2019-01-15', 10);
INSERT INTO FULLORDER VALUES
(1013, DATE '2019-01-15', 1);
INSERT INTO FULLORDER VALUES
(1014, DATE '2019-01-15', 7);
INSERT INTO FULLORDER VALUES
(1015, DATE '2019-01-15', 20);
INSERT INTO FULLORDER VALUES
(1016, DATE '2018-01-20', 7);
INSERT INTO FULLORDER VALUES
(1017, DATE '2018-01-23', 20);
INSERT INTO REQUEST VALUES
(1001, 106, 2);
INSERT INTO REQUEST VALUES
(1001, 102, 2);
INSERT INTO REQUEST VALUES
(1001, 104, 1);
INSERT INTO REQUEST VALUES
(1002, 103, 3);
INSERT INTO REQUEST VALUES
(1003, 103, 4);
INSERT INTO REQUEST VALUES
(1004, 208, 2);
INSERT INTO REQUEST VALUES
(1004, 104, 1);
INSERT INTO REQUEST VALUES
(1005, 104, 4);
INSERT INTO REQUEST VALUES
(1006, 104, 2);
INSERT INTO REQUEST VALUES
(1006, 103, 2);
INSERT INTO REQUEST VALUES
(1006, 102, 2);
INSERT INTO REQUEST VALUES
(1007, 106, 4);
INSERT INTO REQUEST VALUES
(1007, 102, 5);
INSERT INTO REQUEST VALUES
(1008, 103, 1);
INSERT INTO REQUEST VALUES
(1008, 208, 1);
INSERT INTO REQUEST VALUES
(1010, 104, 5);
INSERT INTO REQUEST VALUES
(1010, 107, 4);
INSERT INTO REQUEST VALUES
(1011, 208, 5);
INSERT INTO REQUEST VALUES
(1012, 106, 1);
INSERT INTO REQUEST VALUES
(1013, 106, 2);
INSERT INTO REQUEST VALUES
(1013, 209, 1);
INSERT INTO REQUEST VALUES
(1014, 101, 1);
INSERT INTO REQUEST VALUES
(1015, 102, 1);
INSERT INTO REQUEST VALUES
(1016, 103, 1);
INSERT INTO REQUEST VALUES
(1017, 104, 2);
COMMIT;
-- display tables
SELECT * FROM CUSTOMER;
SELECT * FROM PRODUCT;
SELECT * FROM FULLORDER;
SELECT * FROM REQUEST
1. Give the names and zips of all customers whose names contain the word ‘Home’.
2. For each state with at least one customer in it, give the name of the state and how many customers are in that state. Give the states in alphabetical order.
3. For each date on which at least one order has been placed, give the date and the highest orderID of the orders placed on that date. Sort the output by the date, from latest to earliest.
4. Give the price and description of all products that cost more than four hundred dollars, from the most expensive product to the least expensive product.
If you have any doubts, please give me comment...
-- 1. Give the names and zips of all customers whose names contain the word ‘Home’.
SELECT Name, Zip
FROM CUSTOMER
WHERE Name LIKE '%Home%';
-- 2. For each state with at least one customer in it, give the name of the state and how many customers are in that state. Give the states in alphabetical order.
SELECT State, COUNT(*) no_of_customers
FROM CUSTOMER
GROUP BY State
ORDER BY State;
-- 3. For each date on which at least one order has been placed, give the date and the highest orderID of the orders placed on that date. Sort the output by the date, from latest to earliest.
SELECT OrderDate, MAX(orderID)
FROM FULLORDER
GROUP BY OrderDate
ORDER BY orderDate DESC;
-- 4. Give the price and description of all products that cost more than four hundred dollars, from the most expensive product to the least expensive product.
SELECT Price, Description
FROM PRODUCT
WHERE Price > 400
ORDER BY Price DESC;
-- drop tables DROP TABLE REQUEST CASCADE CONSTRAINTS; DROP TABLE FULLORDER CASCADE CONSTRAINTS; DROP TABLE PRODUCT...
-- drop tables DROP TABLE REQUEST CASCADE CONSTRAINTS; DROP TABLE FULLORDER CASCADE CONSTRAINTS; DROP TABLE PRODUCT CASCADE CONSTRAINTS; DROP TABLE CUSTOMER CASCADE CONSTRAINTS; -- create and link tables CREATE TABLE CUSTOMER ( CustomerID INTEGER, Name VARCHAR2(40), City VARCHAR2(20), State CHAR(2), Zip CHAR(5), CONSTRAINT PK_CUSTOMER PRIMARY KEY (CustomerID) ); CREATE TABLE PRODUCT ( ProductID INTEGER, Description VARCHAR2(30), Material VARCHAR2(20), Price NUMBER(5,2), CONSTRAINT PK_PRODUCT...
Here is the P4 university database ---Drop tables --Drop Table FACULTY Cascade Constraints; --Drop Table OFFERING Cascade Constraints; --Drop Table STUDENT Cascade Constraints; --Drop Table COURSE Cascade Constraints; --Drop Table ENROLLMENT Cascade Constraints; Create Table STUDENT( Std_ID NUMBER(3) Constraint Student_STD_ID_FK PRIMARY KEY, Std_FN Varchar2 (9), Std_LN Varchar2 (8) , Std_City Varchar2 (10), Std_State Varchar2 (4), Std_Zip Number (5), Std_Major Varchar2 (6), Std_Class Varchar2 (3), Std_GPA NUMBER (3,2)); ---Insert records into Student Insert Into STUDENT Values( 101, 'Joe', 'Smith','Eau Clare','WI',18121,'IS','FR',3.8); Insert...
I need help for SQL homework. the question: the code for part 1,2: drop table Customer; drop table Company; drop table Cruise; drop table TravelAgent; drop table Reservation; drop sequence customerID_seq; drop sequence cruiseID_seq; drop sequence travelAgentID_seq; drop sequence reservationID_seq; create table Customer( customerID number, firstName varchar2(15), lastName varchar2(15), address varchar2(30), phone number(10) not null, age number(3), Constraint Customer_PK Primary Key (customerID), constraint Customer_unique unique (firstName,lastName,phone), constraint Customer_check check(phone is not null) ); create sequence customerID_seq start with 1 increment...
drop table department cascade constraints; create table department ( Dname varchar2(15) not null, Dnumber int not null, Mgr_ssn char(9) not null, mgr_start_date Date, primary key (Dnumber), Unique (Dname)); insert into DEPARTMENT values ('Research', '5', '333445555', '22-May-1988'); insert into DEPARTMENT values ('Administration', '4', '987654321', '01-Jan-1995'); insert into DEPARTMENT values ('Headquarters', '1', '888665555', '19-Jun-1981'); drop table employee cascade constraints; create table employee ( Fname varchar2(15) not null, Minit char(1), Lname varchar2(15) not null, Ssn char(9), Bdate date, Address varchar2(30), Sex char(1),...
Display all customers. If a customer has placed any orders, also display the highest..... Tables: CREATE TABLE Sales.Customers ( CustomerId INT NOT NULL IDENTITY, CustomerName NVARCHAR(50) NOT NULL, StreetAddress NVARCHAR(50) NULL, City NVARCHAR(20) NULL, [State] NVARCHAR(20) NULL, PostalCode NVARCHAR(10) NULL, Country NVARCHAR(20) NULL, Contact NVARCHAR(50) NULL, Email NVARCHAR(50) NULL, CONSTRAINT PK_Customers PRIMARY KEY(CustomerId) ); CREATE TABLE HR.Employees ( EmployeeId INT NOT NULL IDENTITY, FirstName NVARCHAR(50) NOT NULL, LastName NVARCHAR(50) NOT NULL, BirthDate DATE NOT NULL, HireDate DATE NOT NULL, HomeAddress...
--- Paper Review drop table paper_review cascade constraint; drop table paper_author cascade constraint; drop table paper cascade constraints; drop table author cascade constraints; drop table reviewer cascade constraints; create table reviewer ( rid int, --- reviewer id rname varchar(50), --- reviewer name remail varchar(50),-- reviewer email raffiliation varchar(50),-- reviewer affiliation primary key (rid) ); insert into reviewer values(1,'Alex Golden', '[email protected]','UMBC'); insert into reviewer values(2,'Ann Stonebraker', '[email protected]','UMD'); insert into reviewer values(3,'Karen Smith', '[email protected]','UMB'); insert into reviewer values(4,'Richard Wallas', '[email protected]','UMBC'); insert into...
-- echo Building demo tables. Please wait. DROP TABLE EMP CASCADE CONSTRAINTS; DROP TABLE DEPT; DROP TABLE SALGRADE; DROP TABLE Prod CASCADE CONSTRAINTS; DROP TABLE Vend; CREATE TABLE DEPT ( DEPTNO NUMBER(2) NOT NULL, DNAME CHAR(14), LOC CHAR(13), CONSTRAINT DEPT_PRIMARY_KEY PRIMARY KEY (DEPTNO)); INSERT INTO DEPT VALUES (10,'ACCOUNTING','NEW YORK'); INSERT INTO DEPT VALUES (20,'RESEARCH','DALLAS'); INSERT INTO DEPT VALUES (30,'SALES','CHICAGO'); INSERT INTO DEPT VALUES (40,'OPERATIONS','BOSTON'); CREATE TABLE EMP ( EMPNO NUMBER(4) NOT NULL, ENAME CHAR(10), JOB CHAR(9), MGR NUMBER(4) CONSTRAINT EMP_SELF_KEY...
An online company sells hundreds of office supply products on its e-Commerce store. It has asked you to design and implement a sales order processing system which will be used by users in our Operations department to process sales orders. Here is an overview of the sales order process. Customers make purchases by placing orders. Each customer has a customer number and profile (such as name, shipping address). To simplify the matter, each time an order is placed, only one...
oracle only database: DROP TABLE ORDERITEMS; DROP TABLE Orders; DROP TABLE BOOKAUTHOR; DROP TABLE BOOKS; DROP TABLE PROMOTION; DROP TABLE AUTHOR; DROP TABLE CUSTOMERS; DROP TABLE PUBLISHER; CREATE TABLE Customers ( Customer# NUMBER(4), LastName VARCHAR2(10) NOT NULL, FirstName VARCHAR2(10) NOT NULL, Email VARCHAR(40), Address VARCHAR2(20), City VARCHAR2(12), State VARCHAR2(2), Zip VARCHAR2(5), Referred NUMBER(4), Region CHAR(2), CONSTRAINT customers_customer#_pk PRIMARY KEY(customer#) ); INSERT INTO CUSTOMERS VALUES (1001, 'MORALES', 'BONITA', '[email protected]', 'P.O. BOX 651', 'EASTPOINT', 'FL', '32328', NULL, 'SE'); INSERT INTO CUSTOMERS VALUES...
Still working on SQL, but now trying to run some commands to pull data from the databases. The last 3 statements Im getting errors but I am not sure how to fix them. What do I need to do differently to those statements to make it work? create table Employee( EmpID char(10), Name varchar2(50), Salery char(10), Address varchar2(50), HireDate date, Phone char(10), Primary key(EmpID)) ; create table Inventory( ProductID char(10), ProductName varchar2(50), UnitPrice char(10), CurrentInventory char(10), MonthlySales char(10), PrecentOfPrice char(10),...