relational database principles
- Apply your knowledge of relational database principles and theory to create effective and efficient database designs
- Define, create and manage relational database systems using SQL
Marks are distributed as follows:
|Question 1: Relational algebra
|Question 2: SQL Select queries
|Question 3: Further SQL
|Question 4: Normalisation
|Question 5: Conceptual design
Question 1: Relational algebra (20 marks)
You are working with a database that stores information about suppliers, parts and projects. The Supply relation records instances of a Supplier supplying a Part for a Project.
The schema for the database used in this question is as follows: (note that primary keys are shown underlined, foreign keys in bold).
SUPPLIER (SNo, SupplierName, City)
PART (PNo, PartName, Weight)
PROJECT (JobNo, JobName, StartYear, Country)
SUPPLY (SNo, PNo, JobNo, Quantity)
Provide relational algebra (NOT SQL) queries to find the following information. Each question is worth 2 marks.
- You can use the symbols s, P, etc or the words ‘PROJECT’, ‘RESTRICT’ etc as you prefer.
- You do not need to try to make efficient queries – just correct ones.
- Where you use a join, always show the join condition.
- List the quantity of parts supplied on JobNo 4745.
- List the weight of the Part named “Left-handed screwdriver”.
- List the Project name and Part name of any Parts where fewer than 500 of the part has been supplied to a particular project.
- List the name of any Suppliers who have supplied Parts to the Project called “New Academic Building” or to the Project called “Removal of Asbestos”.
- List the name of any Suppliers who have supplied Parts to the Project called “New Academic Building” and to the Project called “Removal of Asbestos”.
- List the names of Suppliers who have supplied the Part with the name “Fufful Valve”.
- List the names of Projects that have had Parts supplied by “Insightly Co#” or a Supplier located in Dubai.
- List the details of any supplier who has supplied parts to a project that stared in 2020 and (the project is) located in Singapore.
- List the name of any part that was not used on a project that commenced in 2020.
- List the name of any part that has been supplied to all projects that commenced in 2020.
Question 2: SQL – SELECT queries (20 marks)
Provide SQL queries and the result tables for the following (20 marks):
Please ensure that you include the result table as well as your SQL; you can copy and paste this from either your ssh client or SQL Developer. Each query is worth 2 marks. These tables exist in arion and are owned by the user dtoohey. You may, if you wish, create your own copies of the tables under your own account. If you do so, you should ensure that you copy the sample data in dtoohey’s tables.
These queries are based on the View Ridge Gallery database you have been using in the Lab sessions. Please see Chapters 6 and 7 of Kroenke for background to the case and table structures.
Marks are allocated not only for correct answers, but also for best practice in the creation of the queries.
- List the details of any works of art (including the Artist who created the work) that have more than three copies recorded in the database.
- List the details of any work of art (including the Artist who created the work) that has a Surrealist style.
- List the details of the works of art (including the Artist who created the work, and the acquisition and asking price details) currently held in the gallery (e., works of art that have not been sold).
- List the sales for each customer (e., when a customer purchases a work of art from the Gallery, a transaction line is created. For a purchase, there will be values in the DateSold and SalesPrice columns). The query should include the details of the customer, the transaction and the work of art purchased.
- List the names of the deceased artists and the number of years of age they were when they died (for example, an artist born in 1950 and deceased in 2001 has an age of 51).
- The sum of the acquisition price of works of art for each year (for example, if there were two works of art purchased for $1500 and $1000 in 2019, and one work of art purchased for $500 in 2020, then the sums would be $2500 and $500, for 2019 and 2020 respectively).
- Calculate the profit made on works of art that have been sold (e., the profit/loss on an individual work of art is the difference between the acquisition price and the sales price).
- Which artist has had the most works of art sold, and how many of the artist’s works have been sold?
- Sales of which artist’s works have resulted in the highest average profit (e., the average of the profits made on each sale of works by an artist), and what is that amount?
- Customer name of any customers who have an interest in ALL artists
Question 3: Further SQL (15 marks)
- Provide ALL of the SQL statements required to insert the details of the following: A customer, John Smith, of 47 Moodle Street, Highwater, WA, 6709, Australia (email: email@example.com) has sold a work of art called “Gorillas in the Mist” by the renowned French artist, Gallic Symbol (b. 1972) to the Gallery (e., the Gallery purchased it from him). It is a unique Watercolour on Paper and is 45 * 35cm signed by the Artist. The purchase price was $4600 and the transaction took place on 27th July 2020. (7 marks)
- You have been given the following specifications of a simple database for a netball association that keeps record of players, teams and matches.
Give the SQL to create the Match table. You may assume that the Player and Team tables have already been created, and that the PlayerID and TeamID colums are of the data type VARCHAR2(5). The result of the match refers to the result for the HomeTeam and can be only W, L or D (win, lose or draw). (5 marks)
- Your match table must also include a column that records the scores of both teams in the match. Provide the SQL to amend the original table design to allow for this change in requirement. It is most unlikely (impossible) that a team would ever score more than 999 goals in a match. (3 marks)
Question 4: Normalisation (20 marks)
The following question is based upon the Patient-Treatment relation which records the details of transactions occurring in a medical surgery. You may assume the data are representative.
You have been asked to design a relational database for this system. You know that there are problems with the current design and that it will need to be modified in order to work effectively.
You need to write a 1-2 page report that addresses the following:
- What are the specific problems associated with the current design and why do they arise?
- How would you change the current design and how does your new design address the problems you have identified with the current design.
In order to receive high marks for this question, you will need to demonstrate an understanding of the theories discussed in Topics 1, 2 and 3, how they apply to this problem, and justify the changes you are making to the system. Simply providing the amended design (even if it is correct) will only attract a small percentage of the marks for this question.
Question 5: Conceptual Design (25 marks)
Terrific Airlines is a newly formed airline aimed at the burgeoning market of clandestine travellers (fugitives, spies, confidence tricksters, scoundrels, deadbeats, cheating spouses, politicians, etc.). Terrific Airlines needs a database to track flights, customers, fares, airplane performance, and personnel assignment. Since Terrific Airlines is promoted as a “…fast way out of town,” individual seats are not assigned, and flights of other carriers are not tracked. More specific notes about Terrific Airlines are listed below:
- Information about a route includes its unique number, its origin, its destination, and estimated departure and arrival times. To reduce costs, Terrific Airlines only has non-stop flights with a single origin and destination.
- Flights are scheduled for a route on one or more dates with an airplane and a crew assigned to each flight, and the remaining capacity (seats not taken) noted. In a crew assignment, the employee number and the role are noted. It is a government requirement that the number of hours that flight crew (i.e., pilots, co-pilots, engineers) are in flight must be recorded. There is no such requirement for Non-flight crew (e.g., attendants).
- Airplanes have a unique serial number, a model, a capacity, and a next-scheduled-maintenance date.
- The maintenance record of an airplane includes a unique maintenance number, a date, a description, the serial number of the plane, and the employee responsible for the repairs.
- Employees have a unique employee number, a name, a phone, and a job title.
- Customers have a unique customer number, a phone number, and a name (it may or may not be their own).
- A record is maintained of flight reservations including a unique reservation number, a flight number, a customer number, a date, a fare, and the payment method (usually cash but occasionally some else’s cheque or credit card). If the payment is by credit card, a credit card number and an expiration date are part of the reservation record.
What you have to do:
- Create an entity-relationship diagram showing the data requirements of the system. Your ERD should be able to be implemented in a relational DBMS. You should use the ERD notation we have been using in the lectures, and should include a legend to explain the notation. You should include attributes in the ERD. The use of a drawing tool such as Visio will make this task easier. However, whichever tool you use, you must copy and paste the ERD into a word-processed document. This is because your tutor might not have access to the tools you have used. Please note that hand-drawn ERDs are not acceptable.
- List and explain any assumptions you have made in creating the data model.
Some important things to note:
- Part of understanding a system at sufficient enough detail to model well, involves asking appropriate questions. If you are not sure about some detail of the case study, you should ask on the Discussion Forum in LMS.
- The University email server strips out any Visio (.vsd) files that are sent; even if they are included in a zip archive. So, if you want to send a draft of your design to your lecturer by email, you will need to change the extension to something other than .vsd (.blah works well) or paste the diagram into a word document.
- Marks will be allocated to each of the following functional areas:
- Have you included all required entities in the design?
- Have you included specialisation hierarchies where appropriate?
- Have you designed relationships between the entities that will support the functional requirements?
- Are your relationships correctly annotated?
- Will the overall design support the enterprise requirements?
As Assignment 2 will require you to implement the Terrific Airlines database, you will need to take into account the feedback you receive on your conceptual design when commencing your logical and physical designs.