Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Question 1

1. Create a new database with name upgraddbms. If a database of this name already
exists in your MySQL server, choose some other name for this database.
2. Now create 3 tables with the following attributes and their data-types. Remember that
attributes with underline are primary key attributes.
a. product (product_id int, name varchar(50), quantity int, price float, seller
varchar(50))
b. customer (cust_id int, name varchar(50), address varchar(100))
c. purchase (cust_id int, product_id int, dop date). In the purchase table,
cust_id and product_id are foreign key dependencies in customer and product
tables respectively.
3. After creation of the tables, we realize that the product table must have another attribute
“unit” after quantity. Write the “alter table” command to add this attribute after
“quantity”.

Question 2
1. Add the following row to the product table (product_id int, name varchar(50),
quantity int, unit varchar(50), price float, seller varchar(50)). The values are in the
same sequence as the attributes mentioned
a. 999, USB-C Charger, 1, pieces, 200, Electron Traders
2. Add the following row to the customer table (cust_id int, name varchar(50), address
varchar(100)). The values are in the same sequence as the attributes mentioned
a. 7777, “Deep Kasturi”, “Shivaji Nagar, Mumbai”
3. Update the cust_id of the row added in the previous question from 7777 to 7788.

Question 3:
1. Create 3 different CSVs with names Customers.csv, Products.csv and Purchase.csv
with data consistent with the attribute types, and import them into the table using MySQL
Workbench’s import CSV functionality on a table. You can select the values according to
your choice. Each CSV file must have at least 4 records.

(Note: The solution pdf must contain the screenshot of the output displaying the records
that are imported from the CSV file. You are also required to add the screenshot of the 3
CSV files created and the data inside CSV files. You can refer to the Steps for Importing
CSV file into the table document attached in the Module Conclusion segment of module
1.)

Powered by upGrad Education Private Limited


© Copyright. UpGrad Education Pvt. Ltd. All rights reserved
Question 4:
Write the following query in MySQL in 3 different ways -

a. Using UNION
b. Using a nested-subquery
c. Without UNION or nested-subqueries by just using the standard SELECT, FROM,
WHERE clauses.

Get all the product_ids that are either purchased on 2020-03-15 or 2020-03-16. Remember that
if these dates do not exist in the rows you added in the previous exercise, then choose any two
dates that exist in your purchase table. Otherwise, you will get empty results.

Question 5:

Remember that MySQL does not support the INTERSECT clause. However, we saw in SQL
sessions, how SQL’s syntactic sugar provides a way to write the same logic using different syntax.
So re-write the following query without INTERSECT clause.
(SELECT cust_id FROM Purchase WHERE dop= “2020-04-15”)
INTERSECT
(SELECT cust_id FROM Purchase WHERE dop= “2020-06-15”)
Remember that if these dates do not exist in the rows you added in the previous
exercise, then choose any two dates that exist in your purchase table. You may
get empty results if either the dates do not exist in your table or if they do not have
any common cust_id.

Question 6:
Write the following query using GROUP BY and HAVING clauses in MySQL.
From the purchase table, group all the rows according to cust_ids. Choose a
cust_id if that customer has made more than 2 purchases, and also choose the
total number of purchases the customer has done.

Powered by upGrad Education Private Limited


© Copyright. UpGrad Education Pvt. Ltd. All rights reserved
Question 7:
Write the following query logic in MySQL using nested subqueries and

● Using ALL clause


● NOT IN clause
● Using OUTER JOINS.

Choose all the product_ids that have never been purchased by a customer with cust_id 2222
(Choose a different cust_id, if this ID does not exist in the data you have added).

Question 8

1. Create a variety of CSV files using the Python data generator script provided along with
the lab exercises. The default script creates CSV files with only integer columns, but you
can use the script as a template to create CSVs with string valued columns too. Create
corresponding tables in MySQL and import data of these CSVs into the respective tables.

Question 9
1. Use the “show index” command to check default indexes on the tables created in question
8. If a table has a primary key, then MySQL creates a default primary key clustered index.
2. Create other unclustered indexes on other columns using “CREATE INDEX” command.
3. Again use the “show index” command to see updated output.

Question 10:
Having installed Hadoop and Hive in Module 3 Lab Session, now perform the following
operations on it.

1) Create a database and table and load the data:

● Create a Database Demo


● Create a new table with the named person with column names personid, name, age,
city and salary
● Create a text file named person.txt with 5 entries and load the data into person table
from person.txt
● Display the person table contents

Powered by upGrad Education Private Limited


© Copyright. UpGrad Education Pvt. Ltd. All rights reserved
2) Create a table and load the data:

● Create another table with name orders with column names orderid, order_date,
personid, amount
● Create a text file named orders.txt with 5 entries and load the data into the orders table
from orders.txt
● Display the orders table contents

3) Perform the following join operations on the two tables created above:
● Inner join
● Left outer join
● Right outer join
● Full outer join

4) Display the id, name and 20% salary of each person from the table.

5) Display the minimum salary of a person whose city is Mumbai.

6) Select the sum of person salaries city-wise.

7) Display the sum of person salaries based on the city having a sum >= 35,000.

8) Display the person’s data in descending order salary-wise.

9) Rename an existing table ‘person’ to ‘persondata’ and display data from it.

10) Display the persondata whose name starts with a.

Question 11
1. Inside a new database (name it Netflix), create a collection whose schema and data values
are given in the table below:

(Insert these records using Mongo Shell)

Type Actor Name Country Date of Release Year of


Release

Movie Michel Mexico 23 December 2016 2016

Movie Gilbert Singapore 20 December 2018 2011

Powered by upGrad Education Private Limited


© Copyright. UpGrad Education Pvt. Ltd. All rights reserved
Movie Shane United States 16 November 2017 2009

Movie Robert United States 1 January 2020 2008

Type Show Name Country Date of Release Year of


Release

TV Show 13 Reasons Why United States 23 August 2019 2016

TV Show 20 Minutes Turkey 15 August 2017 2011

TV Show 13 Reasons Why United Kingdom 1 July 2020 2009

TV Show Elite India 1 December 2020 2008

2. Write a query to return all the data of TV shows and movies.

3. Write a query to return data about 13 Reasons Why.

4. Update the release year of the movie starring Robert from 2008 to 2020.

5. Delete the data of the movies that were released in 2020.

6. Delete the collection through the shell and verify the same through an online interface.

Powered by upGrad Education Private Limited


© Copyright. UpGrad Education Pvt. Ltd. All rights reserved
Question 12
Create a GraphDB using Neo4J desktop client and perform the following operations:

1. Create 4 customer nodes with the data given below.

Customer Name Email Id Age

Daniel Johnston dan_j@example.com 25

Alex McGyver mcgalex@example.com 25

Allison York ally_york1@example.com 31

Joe Baxton joeee_baxton@example.com 24

2. Create 4 product nodes with data of laptops as given in the table below and establish the
relationship named 'BOUGHT' between the customer and product nodes.

Product Title Price Shippability Availability Customers who


brought it

Acer Swift 3 SF314-51- 595 True False Alex McGyver


34TX

Dell Inspiron 15 7577 771 True True Joe Baxton

HP ProBook 440 G4 1477 False True Allison York

Apple MacBook A1534 12 1294 False False Daniel Johnston

Powered by upGrad Education Private Limited


© Copyright. UpGrad Education Pvt. Ltd. All rights reserved
3. Now, assume customers have bought these items (one customer buys only one laptop).
Convey this through the graph by displaying the above graph data.

4. Query the graph database and find the list of customers who bought 'Acer Swift 3 SF314-51-
34TX'.

5. Find all the laptops whose shippability is true.

6. Delete all customers whose age is 25.

7. Delete all nodes along with their relationships. Also, prove that the nodes have been deleted.

8. Visualise the inbuilt movie database of Neo4J and count the number of nodes in the movie
database.

Powered by upGrad Education Private Limited


© Copyright. UpGrad Education Pvt. Ltd. All rights reserved
Disclaimer: All content and material on the upGrad website is copyrighted material, either belonging to
upGrad or its bonafide contributors and is purely for the dissemination of education. You are permitted to
access print and download extracts from this site purely for your own education only and on the following
basis:

• You can download this document from the website for self-use only.
• Any copies of this document, in part or full, saved to disc or to any other storage medium may
only be used for subsequent, self-viewing purposes or to print an individual extract or copy for
non-commercial personal use only.
• Any further dissemination, distribution, reproduction, copying of the content of the document
herein or the uploading thereof on other websites or use of the content for any other
commercial/unauthorised purposes in any way which could infringe the intellectual property
rights of upGrad or its contributors, is strictly prohibited.
• No graphics, images or photographs from any accompanying text in this document will be used
separately for unauthorised purposes.
• No material in this document will be modified, adapted or altered in any way.
• No part of this document or upGrad content may be reproduced or stored in any other web site or
included in any public or private electronic retrieval system or service without upGrad’s prior
written permission.
• Any rights not expressly granted in these terms are reserved.

You might also like