Uploaded by Nithin M

Assignment 1

advertisement
BUAN 6320 Database Foundations for Business Analytics
Spring 2022
Instructor: Dr. James Scott
Assignment #1 – Intro SQL and Oracle
General Instructions
•
•
•
•
•
•
•
•
•
•
Students may study together for the assignment and review each other’s completed work
Students must each complete the assignment by their own hand
Please use the provided word document template
Please save the completed word document into PDF format before uploading
Please submit the PDF file electronically through eLearning before the due date and time
Do not include output – only the SQL
Use table aliases for all tables in all queries (unless otherwise specified)
Column aliases are required for all derived columns including aggregate columns (unless
otherwise specified)
Do not use column aliases unless required as stated previously
If a problem does not ask for a specific sort order, use your best judgement to add a sort
order
Chapter 1 Problems – Database Systems
1. How many records does the file contain? How many fields are there per record?
Ans) The file contains 7 records and 5 fields.
2. What problem would you encounter if you wanted to produce a listing by city? How
would you solve this problem by altering the file structure?
Ans) The city is listed as a complete address within the MANAGER_ADDRESS attribute and it
would be difficult to write a query. The problem can be solved by splitting the
MANAGER_ADDRESS into various attributes like address, city, zip. This could make it easier to
write a query.
ACCT 6320 Assignment 1
Page 1 of 7
3. If you wanted to produce a listing of the file contents by last name, area code, city,
state, or zip code, how would you alter the file structure?
Ans) For the last name, the PRODUCT_MANAGER attribute will need to be split on the basis
of first and last name (PRODUCT_MANAGER_FIRST and PRODUCT_MANAGER_LAST). For the
area code, the MANAGER_PHONE can be split into MANAGER_AREA_CODE and
MANAGER_PHONE. For city, state, zip code the MANAGER_ADDRESS can be altered into
MANAGER _CITY, MANAGER_STATE, MANAGER_ZIP respectively. The more the data is split the
easier in becomes to input queries.
4. What data redundancies do you detect? How could those redundancies lead to
anomalies?
Ans) The manager named Holly B Parker has three separate records. This indicates that the
manager is working on three different projects at the same time. This is redundant and the
projects should be clubbed together so that it will be easier to search or update the manager’s
fields. So everytime the manager changes the address or phone number, they will have to
update it three times separately or else this will cause anomalies in the data.
5. Identify and discuss the serious data redundancy problems exhibited by the file
structure shown in Figure P1.5.
Ans) There are many data reduncies in the figure. Some records under the field EMP_NAME,
JOB_CODE and JOB_CHG_HOUR is repeated several times. For example, if the JOB_CHG_HOUR
rate for each JOB_CODE has to be changed each time sepeterately and if it isn’t updated
separately, it will cause anomalies in the file structure. +
Chapter 2 Problems – Database Models
ACCT 6320 Assignment 1
Page 2 of 7
1. Write the business rule(s) that govern the relationship between AGENT and
CUSTOMER.
Ans) The business rules are:
• One agent can have many customers.
• One customer can have only one agent
2. Given the business rule(s) you wrote in Problem 1, create the basic Crow’s Foot
ERD.
Ans)
Customer
Agent
3. Using the ERD you drew in Problem 2, create the equivalent object representation
and UML class diagram.
Ans)
AGENT
Customer
M
Object Representation
Agent
Customer
1…1
1..*
AGENT_CODE
AGENT_LNAME
AGENT_FNAME
AGENT_INTIAL
AGENT_AREACODE
AGENT_PHONE
UML Class Diagram
ACCT 6320 Assignment 1
Page 3 of 7
4. Identify each relationship type and write all of the business rules.
Ans)
•
•
•
•
•
•
One region can have many stores. But one store can only be located in one region.
The relationship between region and store is One to Many. (1:M)
One store can have many employees. Employee can only work for one store.
The relationship between store and employees us One to Many. (1:M)
A job can be given to many employees. Each employee can only have one job.
The relationship between job and employee is One to Many (1:M).
5. Create the basic Crow’s Foot ERD for DealCo.
Ans)
Region
Store
Employees
Job
6. Identify each relationship type and write all of the business rules.
Ans)
•
•
•
•
•
•
One course can be assigned to many classes. Each class in assigned to only one course.
The relationship between course and class is 1: M.
One class can be assigned to many Enrollments. Each enrollment referes to one class.
The relationship between class and enroll is 1:M
One student can have many enrollments. One enrollment can only be assigned to one
student.
The relationship between student and enroll is 1:M
7. Create the basic Crow’s Foot ERD for Tiny College.
Ans)
Course
ACCT 6320 Assignment 1
Class
Enroll
Student
Page 4 of 7
For the following SQL coding problems use the “University.sql” script to create your tables in Oracle
LiveSQL.
Problem #1 – Retrieving all rows and all columns from a table
For each of our tables, retrieve all rows and all columns.
Tables are Student, Faculty, Offering, Course, and Enrollment
(no need to sort at this point)
SELECT *
FROM student;
SELECT *
FROM faculty;
SELECT *
FROM offering;
SELECT *
FROM course;
SELECT *
FROM enrollment;
Problem #2 – Retrieving a subset of columns from a table and sorting them
both with and without the ASC keyword
Retrieve the student number, student first name, and student last name for all students
Sort the results by student last name then by student first name
Use the ASC keyword on the query
Repeat the query omitting ASC
SELECT stdno, stdfirstname, stdlastname
FROM student
ORDER BY stdlastname ASC, stdfirstname ASC;
SELECT stdno, stdfirstname, stdlastname
FROM student
ORDER BY stdlastname, stdfirstname;
ACCT 6320 Assignment 1
Page 5 of 7
Problem #3 – Retrieving a subset of columns from a table and sorting them on multiple
columns mixing ascending and descending order, using both named and positional notation
Retrieve the student last name, student first name, and GPA for all students
Sort the results by GPA highest first, then by student last name, then by student first name
Use column names to sort (omit ASC)
Repeat the query using positional notation
SELECT stdgpa, stdlastname, stdfirstname
FROM student
ORDER BY stdgpa DESC;
SELECT stdgpa, stdlastname, stdfirstname
FROM student
ORDER BY 1 DESC, 2, 3;
Problem #4 – Retrieving columns from a table both with and without duplicates
Retrieve the student city and class for all students with duplicates
Repeat query without duplicates
SELECT stdcity, stdclass
FROM student;
SELECT DISTINCT stdcity, stdclass
FROM student;
Problem #5 – Retrieving a subset of rows with a single Boolean expression
Retrieve the student last name, student first name, and GPA for all students with a GPA greater
than 3.2
SELECT stdlastname, stdfirstname, stdgpa
FROM student
WHERE stdgpa>3.2;
ACCT 6320 Assignment 1
Page 6 of 7
Problem #6 – Retrieving a subset of rows with multiple complex Boolean expressions
Retrieve the student last name, student first name, and GPA for all students with a GPA
(more than 2.2 and less than 2.7) OR (more than 3.2 and less than 3.8)
SELECT stdlastname, stdfirstname, stdgpa
FROM student
WHERE (stdgpa>2.2 AND stdgpa<2.7) OR (stdgpa>3.2 AND stdgpa<3.8);
Problem #7 – Retrieving a subset of rows with the BETWEEN operator
Retrieve the student last name, student first name, and GPA for all students with a GPA that is
between 2.7 and 3.2 inclusive
SELECT stdlastname, stdfirstname, stdgpa
FROM student
WHERE stdgpa BETWEEN 2.7 AND 3.2;
Problem #8 – Retrieving a subset of rows with testing for NULLs
Retrieve the offer number, course number, year, and faculty number from all course offerings
that has not yet been assigned a Faculty
Repeat query for course offerings that have been assigned a Faculty
SELECT offerno, courseno, offyear, facno
FROM offering
WHERE FACNO IS NULL;
SELECT offerno, courseno, offyear, facno
FROM offering
WHERE FACNO IS NOT NULL;
ACCT 6320 Assignment 1
Page 7 of 7
Download