Question

In: Computer Science

When customers place an order, the order details will need to be stored into the database,...

When customers place an order, the order details will need to be stored into the database, as well as details of the customer. Naturally this will include details such as name, address and phone number. For each order they can order multiple t-shirts. For each t-shirt, they will be allowed to choose:

- The style of the t-shirt

- The sleeve configuration

- The colour of the t-shirt

- The size of the t-shirt

- The text/image/logo to be printed

- The material used for t-shjirt

- The material used for the text/image/logo

It is extremely important to store the data in a structured format, because it will be used to send directly to the automated T-Shirt create equipment to be instantly created and shipped. Customers will be required to pay before the products are sent so details will need to be kept of the payment. Your friends are planning to accept payment by credit card, direct bank deposit and paypal. For credit cards they need to store the credit card number and expiry date, for direct deposit they need a field to tick off that the payment has appeared in their bank account and for paypal they again need a field to tick off plus the paypal user id of the payer.

Sample T-Shirt T-Shirt Attrribute Data

Type:

Shirt_Material:

Sleeve:

Shirt_Colour:

Extras:

Extras_Material:

Extras_Font

Extras_colour

Size:

Standard

Cotton

Short

White

Text “SAMPLE T-SHIRT”

Ink

48 Time New Roman

Orange

XL

Type:

Shirt_Material:

Sleeve:

Shirt_Colour:

Extras:

Extras_Material:

Extras_Font

Extras_colour

Size:

Standard

Leather

Short

Black

-

-

-

-

M

REQUIREMENTS – PASS/CREDIT – DATA MDOEL

Create an ER diagram, relational model and any business rules or assumptions made.

REQUIREMENTS – HIGHER LEVEL – SQL IMPLEMENTATION

For additional marks, provide the SQL commands to create the tables and insert a few rows into each table. Also provide several business question and SQL queries to test out the tables, include at least a:

• SELECTION condition query

• GROUP BY query

• JOIN query

• NESTED query

Also create a least one visualisation of the data using Orange/Tableau/Excel.

Solutions

Expert Solution

REQUIREMENTS – PASS/CREDIT – DATA MDOEL

Create an ER diagram, relational model and any business rules or assumptions made.

Let’s identify the Entities in the system:

  1. Customer
  2. Order
  3. T-Shirt
  4. Payment

ER Diagram for the system given:

Relation Model for the above System:

NOTE: primary key is denoted as underlined, foreign key is having (fk) next to the column name.

  1. Customer(id, name, state, city, zipcode, phonenumber)
  2. OrderRecords(order_id, order_date, customer_id(fk), payment_id(fk),status)
  3. Tshirt(shirt_id, type,size, shirt_material, extras, sleeves, extras_font, extras_color, extras_material)
  1. Payment(payment_id, pay_type, amount, cardExpiry,cardNumber, paypalID, isAmountRecieved)

-------------------------------------------------------------------------

REQUIREMENTS – HIGHER LEVEL – SQL IMPLEMENTATION

---------------------------------------------------------------------------

Create table queries

Create customer table:

CREATE TABLE customer(Id varchar(20) PRIMARY KEY, name varchar, state varchar(20), city varchar(20), zipcode varchar(20), phoneNumber varchar(20) );

Create tshirts table:

CREATE TABLE tshirt(shirt_id int PRIMARY KEY, type varchar(20), size char(8) check (size in ('S','M', 'L', 'X', 'XL' ,'FREE')) ,shirt_color varchar(20) , shirt_material varchar(20), extras char(8) check (extras in ('Logo','Image','Text')), sleeves varchar(20), extras_font varchar(20),extras_color varchar(20), extras_material varchar(20) );

Create payment table:

CREATE TABLE payment(payment_id int PRIMARY KEY, pay_type varchar(20), amount double, cardExpiry varchar(7), cardNumber varchar(20), paypalId varchar(20), isamountrecieved char(4) check (isamountrecieved in ('YES','NO')) );

Create orderDetails table:

CREATE TABLE orderRecords (order_id int primary key,order_date DATETIME, CUSTOMER_ID varchar(20) references customer(Id),payment_id int references payment(payment_id), status varchar(20));

Inserting rows in each table

Insert into customer table

Query:

INSERT INTO customer (Id, name, state, city, zipcode, phoneNumber)

VALUES ('C003','Albert','Rjht','Urinda','1345','173-654987');

Output: After adding similar 3 records, below will be the records available n the table

Insert into tshirt table

Query:

INSERT INTO tshirt(shirt_id, type , size ,shirt_color, shirt_material, extras , sleeves , extras_font ,extras_color , extras_material )

Values (1, 'standard', 'M', 'White', 'cotton', 'Text', 'half', 'airial', 'Red', 'Rubbur');

Output: Running the above query will add the data in the table as below:

Insert into payment table:

Query: The below query will add a payment of direct debit type which will not require data for cardNumber, cardExpiry and PaypalID

INSERT INTO payment(payment_id , pay_type , amount, cardExpiry, cardNumber, paypalId , isamountrecieved )

Values (1, 'directdeposit', 1200, 'NA','NA','NA' , 'YES')

Output: Running the above query will add the data in the table as below:

Insert into orderRecords table:

Query:

INSERT INTO orderRecords (order_id ,order_date, CUSTOMER_ID ,payment_id, status)

Values (1, '2019-09-12' , 'C001', 1, 'Pending')

Output:

Business SQL Queries Examples

• Select : Select the customers where the customer id is C001

Query:   select * from customer where Id = 'C001';

Output: The result will show the customer record with id C001

• Group By: Retrieve the count of the customers by the state in customer table

Query: Select state, count(*) as customerCount from customer group by state;

Output: The result will count the number of customers in different states and display the count under ‘customerCount’ column

• JOIN query: Find the customer name along with order id and order date placed using join on orderRecords and customer tables

Query: select customer.name, orderRecords.order_id , orderRecords.order_date

FROM orderRecords INNER JOIN customer ON orderRecords.CUSTOMER_ID=Id;

Output: The output will join the two tables and display the below result:

• NESTED query: Use nested query to find the customer record where the customer name is ‘Adam’

Query: select * from customer where id in (select id from customer where name = 'Adam')

Output:


Related Solutions

Explain how Apple Inc. customers will place an order, how the order will be delivered and...
Explain how Apple Inc. customers will place an order, how the order will be delivered and how the process for complaints will be handled.
Database administrators use backups and replication to protect data stored in a database. Compare and contrast...
Database administrators use backups and replication to protect data stored in a database. Compare and contrast the two operations. Describe a business application scenario, and provide and discuss a sample query of a common backup or restore operation.
In order to move from one place to another in the cell fatty acids need to...
In order to move from one place to another in the cell fatty acids need to associate with lipid chaperones. Why are these chaperones required, and what is the name of this group of proteins that are responsible for this trafficking of fatty acids within the cell? What is the main distinguishing feature of these proteins that makes it possible for fatty acids to move within the cell?
The advantages of a relational database include limiting the amount of redundant data that are stored...
The advantages of a relational database include limiting the amount of redundant data that are stored in a database. Why is this an important advantage? What can go wrong when redundant data are stored?
provide 3 different data items collected and stored in the PMS database
provide 3 different data items collected and stored in the PMS database
Need SQL commands for these questions based on the bowling league database; When was the first...
Need SQL commands for these questions based on the bowling league database; When was the first tournament date and where was it played? What are the number of tournaments per location?
You need to study the satisfaction of customers of a specific restaurant. You decide to order...
You need to study the satisfaction of customers of a specific restaurant. You decide to order food and talk to those customers sitting next to you. This would most closely describe which type of sampling technique? Convenience Systematic Stratified Random
Alsalam manufactures undertakes works against customers order. The following details relates to December 31st 2019 During...
Alsalam manufactures undertakes works against customers order. The following details relates to December 31st 2019 During the month December the company procured raw material worth OMR 150,000.During this period the company has undertaken different jobs. The factory overhead rate is estimated at 130% of direct labour cost but actual factory overhead incurred is OMR 68,000. The company purchased a machinery on 01.01.2019 at OMR 500,000 to be depreciated at 10% p.a. Other important information is given below: Jobs completed No:301,303,304,305...
A grocery store chain like Tesco Malaysia need to be responsive and be able provide customers what they need, when they need it, where they need it.
A grocery store chain like Tesco Malaysia need to be responsive and be able provide customers what they need, when they need it, where they need it.Determine FOUR (4) responsive approaches that can be taken by a convenience store supply chain to be responsive?Based on above answers, describe TWO (2) risks in above approaches?
When considering The Right to Food Timeline, place the following in correct order: Answers Adoption of...
When considering The Right to Food Timeline, place the following in correct order: Answers Adoption of the 2030 Agenda for Sustainable Development Appropriation of the Principles for Responsible Investment in Agriculture and Food Systems UN Convention on the Rights of Persons with Disabilities Initiation of the Millenium Development Goals CESCR General Comment 12: The Right to Adequate Food World Food Summit World War II Adoption of the Universal Declaration of Human Rights UN Convention on the Elimination of All Forms...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT