A database used for a toy store that keeps track of the inventory and purchase orders from the store. All clients will have their membership ID card to shop. This database will help the store to keep track of their orders. It will also help the store to know how many products are available in the inventory. It is necessary to have a membership to purchase a product. The customer can also bring coupons to get discount.
Key attributes:
Salesman: salesmanID, name, lastName, telephone, sex, birthdate,
direction, email,
salaryPerHour, hourWork.
Customer: customerID, name, lastName, direction, telephone.
Coupon: Coupon_Code, discountedPrice.
Order: OrderID, SalesmanID, MembershipD., Orderdate.
ORDER AND PRODUCT WILL HAVE A MIX TABLE: OrderID, ProductID.
Product: ProductID, name, price, brand, description, quantity
Membership: MembershipID, CsitomerID. OrderNo
Store: StoreIDdirection, telephone, email, owner
NOTE: direction is a summarized form of street name, city, and zip
code.
Create a simple SQL database
Use Cases:
Check product quantity
Salesman works at a store
Store stores products
Once the salesman can check the productID, he can check the
quantity.
List all orders done by a specific customer
Salesman can view customer information using their unique
membership ID card.
Each order will have membership ID as a foreign key, which helps
the salesman pull out all the orders related to a specific
membership.
Check who sold a specific product
A product will be part of an order
Each order will have a foreign key representing the person who
placed the order and the salesman who served the customer in a
specific order.
Which day a specific product was sold
Salesman checks orders and their date.
Each order will have products.
Once the salesman know the order containing a specific product, he
can pull out the date the order was made.
CREATE DATABASE
first you need to create database for your toy store by using following command:
CREATE DATABASE TOYSTORE;
2. CREATE TABLES
Second you need to create table to store all
information about part of your organization in the database.
Salesman table:
CREATE TABLE SALESMAN(salesmanID INT NOT NULL,name VARCHAR(20) NOT NULL,
lastName VARCHAR(20) NOT NULL, telephone INT NOT NULL, sex VARCHAR(10) NOT
NULL, birthdate VARCHAR(20) NOT NULL, direction VARCHAR(10) NOT NULL, email
VARCHAR(20) NOT NULL, salaryPerHour INT NOT NULL, hourWork INT NOT NULL,
PRIMARY KEY (salesmanID));
Customer table:
CREATE TABLE CUSTOMER(customerID INT NOT NULL,name VARCHAR(20) NOT NULL,
lastName VARCHAR(20) NOT NULL, direction VARCHAR(10) NOT NULL, telephone INT
NOT NULL,
PRIMARY KEY (customerID));
Coupon table:
CREATE TABLE COUPON(Coupon_code VARCHAR(20) NOT NULL,
discountedPrice DECIMAL NOT NULL,
PRIMARY KEY (Coupon_code));
Order table:
CREATE TABLE ORDER(OrderID INT NOT NULL, salesmanID INT NOT NULL,
membershipID INT NOT NULL, productID INT NOT NULL, Orderdate VARCHAR(20) NOT NULL,
PRIMARY KEY (OrderID),
FOREIGN KEY
(productID) REFERENCES Persons(productID)
FOREIGN KEY (salesmanID) REFERENCES Persons(salesmanID)
FOREIGN KEY (membershipID) REFERENCES Persons(membershipID));
Product table:
CREATE TABLE PRODUCT(productID INT NOT NULL,OrderID INT NOT NULL, name VARCHAR(20) NOT NULL,
price DECIMAL NOT NULL, brand VARCHAR(20) NOT NULL, description
VARCHAR(50) NOT NULL,
quantity INT NOT
NULL,
FOREIGN KEY
(OrderID) REFERENCES Persons(OrderID))
PRIMARY KEY (productID));
Membership table:
CREATE TABLE MEMBERSHIP(membershipID INT NOT NULL, customerID INT NOT NULL,
OrderNo VARCHAR(20) NOT NULL,
PRIMARY KEY (membershipID),
FOREIGN KEY (customerID) REFERENCES Persons(customerID));
Store table:
CREATE TABLE STORE(storeID INT NOT NULL,direction VARCHAR(20) NOT NULL,
telephone INT NOT NULL, email VARCHAR(20) NOT NULL, owner
VARCHAR(50) NOT NULL,
PRIMARY KEY (storeID));
Direction table:
CREATE TABLE DIRECTION(directionID INT NOT NULL,name VARCHAR(20) NOT NULL,
city VARCHAR(20) NOT NULL, zipcode INT NOT NULL,
PRIMARY KEY (directionID));
USECASES SOLUTION:
1) CHECK PRODUCT QUANTITY:
SELECT SUM(quantity) as "Total
Quantity"
FROM PRODUCT
2)SALESMAN WORKS AT A STORE:
SELECT COUNT(*) FROM
SALESMAN
3) STORE STORES PRODUCTS:
SELECT COUNT(*) FROM
PRODUCT
4) Once the salesman can check the
productID, he can check the quantity:
SELECT productID,
sum(quantity) as total_quantity
FROM PRODUCT
5)List all orders done by a
specific customer:
SELECT * FROM CUSTOMER
a, ORDER b
WHERE
a.customerID=b.OrderID
AND
b.customerID='02'
6)Salesman can view customer
information using their unique membership ID card.
SELECT * FROM
MEMBERSHIP a, CUSTOMER b
WHERE
a.membershipID=b.customerID
AND
a.membershipID='02'
7)Each order will have membership
ID as a foreign key, which helps the salesman pull out all the
orders related to a specific membership:
SELECT * FROM ORDER a,
MEMBERSHIP b
WHERE
a.OrderID=b.membershipID
AND
a.membershipID='02'
8) Check who sold a specific
product:
SELECT * FROM ORDERS
WHERE ID IN
(SELECT OrderID
FROM ORDER
WHERE
productID = 2
GROUP BY
OrderID
HAVING
COUNT(OrderID) = 1
)
9) A product will be part of an
order:
SELECT * FROM PRODUCT a, ORDER
b
WHERE
a.productID=b.OrderID
10) Each order will have a foreign
key representing the person who placed the order and the salesman
who served the customer in a specific order:
SELECT o.OrderID,
o.membershipID, o.salesmanID
FROM ORDER o
WHERE
o.membershipID=o.salesmanID
11)Which day a specific product was
sold
SELECT * FROM PRODUCT
a, ORDER b
WHERE
a.productID=b.OrderID
AND
b.Orderdate='dd/mm/yyyy'
12) Salesman checks orders and
their date:
SELECT OrderID,
Orderdate FROM ORDER
13)Each order will have
products:
SELECT * FROM ORDER a,
PRODUCT b
WHERE
a.OrderID=b.productID
14) Once the salesman know the
order containing a specific product, he can pull out the date the
order was made.
SELECT o.Orderdate,
o.productID, o.OrderID
FROM ORDER o
WHERE
o.OrderID=o.productID
A database used for a toy store that keeps track of the inventory and purchase orders...
A database used for a toy store that keeps track of the inventory and purchase orders from the store. All clients will have their membership ID card to shop. This database will help the store to keep track of their orders. It will also help the store to know how many products are available in the inventory. It is necessary to have a membership to purchase a product. The customer can also bring coupons to get discount. Key attributes: Salesman:...
Create the following SQL Server queries that access the Northwind database Same as problem 3 but, limit the list to all customers who placed 3 or more orders. The product id, product name, last date that the product was ordered for all items in the Grains/Cereals category. (Hint: Use MAX) The product ID, product name, and number of distinct customers who ordered that product in 1996 Thank you. Categories Customers Employees Order Details Orders Products Shippers 9 CategoryID CategoryName Description...
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...
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...
You are asked to design a data model for The Wagging Tail, an online store that sells products for dogs, e.g. dog collars, dog food, dog toys, dog treats, etc. You want to keep track of three entities: (1) the products that the store sells, (2) customers who purchase the products, and (3) the orders that are made on the website. Draw an ERD diagram and use the following information to help guide your drawing: The database should keep track...
The Northwind database created by Microsoft contains the sales data for a fictitious company called Northwind Traders, which imports and exports specialty foods from around the world. Here is the schema of the database: Products (ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued); Suppliers (SupplierID, CompanyName, ContactName , ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax, HomePage); Categories (CategoryID, CategoryName, Description, Picture); Orders (OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, ShipVia, Freight, ShipName,ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry); Order_details (ID, OrderID,...
use workbench please Task 1: Create a database and name it practical2DB. (2 marks) Task 2: Create all the four tables according to the relational scheme in Figure 1. (8 marks) Task 3: Insert 5 records to into each table. (5 marks) Task 4: Write a query to list alphabetically ordered names, addresses, and IDs of all the customers whose postcode is in (40150, 40400, 47500). (10 marks) Task 5: Delete 1 record from Products table using their primary keys....
The Case Express Delivery (ED) is a Morgantown based home goods company. Customers can call in orders and ED mails the items to the customer. They also email the customers a bill, as seen below. Customers can mail in a check, once they receive the order. ED needs to track whether the order has been paid or not, but the payment information is handled by a third-party vendor. ED needs to create a database to track their customers. Each customer...
This is extra information about the shopping database given to answer this question: For many query questions we refer to the following database schema for a website that keeps track of what people like to buy or actually buy in different on-line supermarkets. (Think of something like a cross-store loyalty card system.) customer(cID, cName, street, city) Customers with unique cID and other attributes store(sID, sName, street, city) Stores with a unique ID and other attributes. Stores with the same name...