Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DATABASES BELOW: CREATE TABLE Categories ( CategoryID INT PRIMARY KEY IDENTITY, CategoryName VARCHAR(255) NOT NULL UNIQUE ); CREATE TABLE Products ( ProductID INT PRIMARY KEY

image text in transcribed

DATABASES BELOW:

CREATE TABLE Categories ( CategoryID INT PRIMARY KEY IDENTITY, CategoryName VARCHAR(255) NOT NULL UNIQUE );

CREATE TABLE Products ( ProductID INT PRIMARY KEY IDENTITY, CategoryID INT REFERENCES Categories (CategoryID), ProductCode VARCHAR(10) NOT NULL UNIQUE, ProductName VARCHAR(255) NOT NULL, Description TEXT NOT NULL, ListPrice MONEY NOT NULL, DiscountPercent MONEY NOT NULL DEFAULT 0.00, DateAdded DATETIME DEFAULT NULL );

CREATE TABLE Customers ( CustomerID INT PRIMARY KEY IDENTITY, EmailAddress VARCHAR(255) NOT NULL UNIQUE, Password VARCHAR(60) NOT NULL, FirstName VARCHAR(60) NOT NULL, LastName VARCHAR(60) NOT NULL, ShippingAddressID INT DEFAULT NULL, BillingAddressID INT DEFAULT NULL );

CREATE TABLE Addresses ( AddressID INT PRIMARY KEY IDENTITY, CustomerID INT REFERENCES Customers (CustomerID), Line1 VARCHAR(60) NOT NULL, Line2 VARCHAR(60) DEFAULT NULL, City VARCHAR(40) NOT NULL, State VARCHAR(2) NOT NULL, ZipCode VARCHAR(10) NOT NULL, Phone VARCHAR(12) NOT NULL, Disabled INT NOT NULL DEFAULT 0 );

CREATE TABLE Orders ( OrderID INT PRIMARY KEY IDENTITY, CustomerID INT REFERENCES Customers (CustomerID), OrderDate DATETIME NOT NULL, ShipAmount MONEY NOT NULL, TaxAmount MONEY NOT NULL, ShipDate DATETIME DEFAULT NULL, ShipAddressID INT NOT NULL, CardType VARCHAR(50) NOT NULL, CardNumber CHAR(16) NOT NULL, CardExpires CHAR(7) NOT NULL, BillingAddressID INT NOT NULL );

CREATE TABLE OrderItems ( ItemID INT PRIMARY KEY IDENTITY, OrderID INT REFERENCES Orders (OrderID), ProductID INT REFERENCES Products (ProductID), ItemPrice MONEY NOT NULL, DiscountAmount MONEY NOT NULL, Quantity INT NOT NULL );

1. (15) Write a script that uses three variables to store (1) the count of distinct orders made in the Orders table (2) the total amount of sales (sales means the price of the item with discount multiplied by the quantity) made in the Orderitems table and (3) the average sales calculated using the first two variables ($909.57). Don't include TaxAmount or shipping costs. 2. (15) Write a script that uses two variables to store (1) the count of all of the products in the Products table and (2) the average list price for all products in the Products table. If the product count is greater than or equal to 7, the script should print a message that displays the values of both variables. Otherwise, the script should print a message that says, "The number of products is less than 7". 3. (25) Write a script that finds (1) The name of the customer who made the largest order (amount of money spent on a single order) and (2) the value of that largest order. Store the name and the value of the order in two different variables and then print using the two variables. A sample print statement with the correct customer and order value- "The largest order of $2799.95 was made by David Goldstein" Hint: This problem may require you to use a table variable to store information that you will use to get to the required information. You may need to use multiple queries. There are multiple ways to solve this

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

=+What key digital strategies and tactics do they adopt?

Answered: 1 week ago