James River Jewelry is a small jewelry shop. While James River Jewelry does sell
ID: 3864919 • Letter: J
Question
James River Jewelry is a small jewelry shop. While James River Jewelry does sell typical jewelry purchased form jewelry vendors, including such items as rings, necklaces, earrings, and watches, it specializes in hard-to-find Asian jewelry. Although some Asian jewelry is manufactured jewelry purchased from vendors in the same manner as the standard jewelry is obtained, many of the Asian jewelry pieces are often unique single items purchased directly from the artisan who created the piece (the term “manufactured” would be an inappropriate description of these pieces). It has a small but loyal clientele, and it wants to further increase customer loyalty by creating a frequent buyer program. In this program, after every 10 purchases, a customer will receive a credit equal to 50 percent of the sum of his or her 10 most recent purchases. This credit must be applied to the next (or “11th”) purchase. Assume that James River designs a database with the following tables. CUSTOMER (CustomerID, LastName, FirstName, Phone, Email) PURCHASE (InvoiceNumber, InvoiceDate, PreTaxAmount, CustomerID) PURCHASE_ITEM (InvoiceNumber, ItemNumber, RetailPrice) ITEM (ItemNumber, Description, Cost, ArtistName) The referential integrity constraints are: CustomerID in PURCHASE must exist in CustomerID in CUSTOMER InvoiceNumber in PURCHASE_ITEM must exist in InvoiceNumber in PURCHASE ItemNumber in PURCHASE_ITEM must exist in ItemNumber in ITEM Assume that CustomerID of CUSTOMER, ItemNumber of ITEM, InvoiceNumber of PURCHASE, and ItemNumber of PURCHASE_ITEM are all surrogate keys with values as follows: CustomerID Start at 1 Increment by 1 InvoiceNumber Start at 1 Increment by 1 ItemNumber Start at 1 Increment by 1 Write SQL statements and answer questions for this database as follows: A. Write SQL CREATE TABLE statements for each of these tables. B. Write foreign key constraints for the relationships in each of these tables. Make your own assumptions regarding cascading deletions and justify those assumptions. (Hint: You can combine the SQL for your answers to parts A and B.) C. Write SQL statements to insert at least three rows of data into each of these tables. Assume that surrogate key column values will be supplied by the DBMS. D. Write SQL statements to list all columns for all tables. E. Write an SQL statement to list ItemNumber and Description for all items that cost more than $100. F. Write an SQL statement to list ItemNumber and Description for all items that cost more than $100 and were produced by an artist with a last name ending with the letters son. G. Write an SQL statement to list LastName and FirstName of customers who have made at least one purchase with PreTaxAmount greater than $200. Use a subquery. H. Answer part G but use a join using JOIN…ON syntax. I. Write an SQL statement to list LastName and FirstName of customers who have purchased an item that costs more than $50. Use a subquery. J. Answer part I but use a join using JOIN…ON syntax K. Write an SQL statement to list LastName and FirstName of customers who have purchased an item that was created by an artist with a last name that begins with the letter J. Use a subquery. L. Answer part K but use a join using JOIN…ON syntax M. Write an SQL statement to show the Name and sum of PreTaxAmount for each customer using JOIN…ON syntax. N. Write an SQL statement to show the sum of PreTaxAmount for each artist (hint: the result will have only one line per each artist). Use a join using JOIN…ON syntax, and sort the results by ArtistLastName in ascending order. O. Write an SQL statement to show the sum of PreTaxAmount for each ArtistName but exclude any items that were part of purchases with PreTaxAmount less than $25. Use a join using JOIN…ON syntax, and sort the results by ArtistLastName in descending order. P. Write an SQL statement to show which customers bought which items, and include any items which have not been sold. Includes CUSTOMER.LastName, CUSTOMER.FIRSTName, InvoiceNumber, InvoiceDate, ItemNumber, ItemDescription, ArtistLastName, and ArtistFirstName. Use a join using JOIN…ON syntax, and sort the results by ArtistLastName and ArtistFirstName in ascending order. Q. Write an SQL statement to modify all ITEM rows with an artist last name of Baxter to an artist first name of Rex. R. Write SQL statements to switch the values of ArtistLastName so that all rows currently having the value Baker will have the value Baxter, and all rows currently having the value Baxter will have the value Baker.
Explanation / Answer
There are many questions clubbed into this one question. As per chegg policy we can only provide answer to first 4 part. But as you are a valued customer for us, I will try to answer all your question. Just make sure to ask one qusetion(can have max. 4 subparts) at a time. Thanks for understanding!
A. Write SQL CREATE TABLE statements for each of these tables.
Answer)
CREATE TABLE CUSTOMER (
CustomerID Integer Primary Key IDENTITY (100,10),
LastName Char(50),
FirstName Char(50) Not Null,
Phone Char(12),
Email VarChar(100)
);
CREATE TABLE PURCHASE (
InvoiceNumber Integer Primary Key,
InvoiceDate Date Not Null,
PreTaxAmount Money Not Null,
CustomerID Integer Not Null
);
CREATE TABLE PURCHASE_ITEM (
InvoiceNumber Integer Not Null,
ItemNumber Integer Not Null,
RetailPrice Money Not Null
);
ALTER TABLE PURCHASE_ITEM ADD CONSTRAINT PurchaseItemPK PRIMARY KEY (InvoiceNumber, ItemNumber);
CREATE TABLE ITEM(
ItemNumber Integer Primary Key,
Description Char(100) Not Null,
Cost Money Not Null,
ArtistName Char(100)
);
B. Write foreign key constraints for the relationships in each of these tables. Make your own assumptions regarding cascading deletions and justify those assumptions.
Answer)
ALTER table PURCHASE ADD CONSTRAINT CustomerFK FOREIGN KEY (CustomerID) REFERENCES CUSTOMER;
ALTER table PURCHASE_ITEM ADD CONSTRAINT PurchaseFK FOREIGN KEY (InvoiceNumber) REFERENCES PURCHASE ON DELETE CASCADE;
ALTER table PURCHASE_ITEM ADD CONSTRAINT ItemFK FOREIGN KEY (ItemNumber) REFERENCES PURCHASE;
C. Write SQL statements to insert at least three rows of data into each of these tables. Assume that surrogate key column values will be supplied by the DBMS.
Answer)
I am giving one one insert command, please repeat it for three values as shown below:
INSERT INTO CUSTOMER VALUES ('1','Raj','Rahul','9876543210',‘rahulraj@somewhere.com’);
INSERT INTO PURCHASE VALUES ('10','03/21/2017','100',‘1’);
INSERT INTO PURCHASE_ITEM VALUES ('10','1','100');
INSERT INTO ITEM VALUES ('1','Bubble gum','100','AnyName');
D. Write SQL statements to list all columns for all tables.
Answer)
SELECT * FROM CUSTOMER;
SELECT * FROM PURCHASE;
SELECT * FROM PURCHASE_ITEM;
SELECT * FROM ITEM;
E. Write an SQL statement to list ItemNumber and Description for all items that cost more than $100.
Answer)
SELECT ItemNumber, Description
FROM ITEM
WHERE Cost > 100;
F. Write an SQL statement to list ItemNumber and Description for all items that cost more than $100 and were produced by an artist with a last name ending with the letters son.
Answer)
SELECT ItemNumber, Description
FROM ITEM
WHERE Cost > 100 AND ArtistName LIKE ‘%son’;
G. Write an SQL statement to list LastName and FirstName of customers who have made at least one purchase with PreTaxAmount greater than $200. Use a subquery.
Answer)
SELECT LastName , FirstName
FROM CUSTOMER
WHERE PURCHASE=(Select atleast one(PreTaxAmount>200));
R.Given your assumptions about cascading deletions in your answer to question B, write the fewest number of DELETE statements possible to remove all of the data in your database, but leave the table structures intact.
Answer)
DELETE FROM PURCHASE;
DELETE FROM ITEM;
DELETE FROM CUSTOMER;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.