Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask DBMS Expert


Home >> DBMS

Assignment - Answer all questions -

Questions 1-6 make use of the following relational schema for a database storing water quality readings.

INSTRUMENT (name, description)

SITE (name, water_depth, description, latitude, longitude)

DEPLOYMENT(id, instrument, site, begin, end)

PROFILE(id,timestamp, deployment)

READING(id, timestamp, profile, depth, temperature, turbidity, dissolved_oxygen, power)

INSTRUMENT describes a type of instrument and SITE is a particular location. DEPLOYMENT captures the deployment of a particular instrument at a particular location; 'begin' and 'end' are the beginning and ending dates of the deployment. 'end' may be NULL for a current deployment.

Water quality profiles are taken several times a day. The timestamp for a profile is the time the profile was started. A profile consists of a number of readings taken at various depths. Each reading has a timestamp indicating when it was taken, the depth at which the reading was taken, and values for several water quality parameters (water temperature, turbidity, and oxygen saturation). Power indicates the battery charge.

All IDs are non-negative integers. The maximum depth is 200m; two decimal places are recorded. Latitude and longitude use the decimal degrees format e.g. 42.818833, -76.960167. Timestamps include both date and time, and must accommodate values since 1/1/2014. Power ranges from 0 to 15, with one decimal place recorded. Temperature ranges from 0 to 40, turbidity ranges from -5 to 100, and dissolved oxygen ranges from -5 to 20. All data values are recorded with two decimal places.

Key attributes are underlined. Foreign key constraints:

  • DEPLOYMENT. instrument and DEPLOYMENT. site refer to INSTRUMENT .name and SITE .name, respectively
  • PROFILE. deployment refers to DEPLOYMENT . id
  • READING.profile refers to PROFILE.id

Additional constraints:

  • A reading must be associated with a profile and must have a depth.
  • A profile must be associated with a deployment.
  • A deployment must have a site and instrument, but the date range is optional.
  • There is at most one reading for a given depth in a particular profile.

Give SQL statement(s) to perform the following tasks. (You do not need to actually do the tasks, just write the statement(s) to accomplish them.) When asked for SQL statements to create something (table, view, stored routine, trigger), you can write the appropriate statement from scratch or you can use MySQL Workbench and copy the SQL statement(s) that it executes when you click "Apply". Use the database username exam2 for anything you want to execute/test in a database.

1. Define the five tables described above. Choose appropriate data types and column attributes, and include all appropriate constraints.

2. Populate the database using the files in /classes/cs343/exam2.

3. (a) Define a view containing the profile ID, reading ID, timestamp, depth, water temperature, turbidity, dissolved oxygen, power, site, and instrument for each reading. Readings recorded when the battery charge is too low are not trustworthy, so only readings where the power is at least 9.5 should be included.

(b) For each profile, report the date and time of the profile, the maximum water temperature in the profile, and the depth at which that temperature occurred. If the maximum water temperature occurred at multiple depths in a profile, include all of those readings. For full credit, make use of the view you defined.

4. (a) Delete all of the readings where the battery power is less than 9.5.

(b) Negative turbidity readings indicate a miscalibrated instrument. Set turbidity readings that are below 0 to 0.

(c) Add a new site named SenecaB with a water depth of 20m at coordinates 42.850987, -76.963802.

5. Define stored routines for each of the following. Choose a procedure or a function as appropriate.

(a) Given a profile ID, determine the number of readings associated with that profile.

(b) Given a profile ID, depth, and water temperature, update the temperature associated with that reading if such as reading exists, otherwise insert a new reading with the specified information.

(c) A thermocline is a thin layer of water where the temperature changes rapidly; it separates the warmer surface water from the colder deep water. Given a profile ID, find the biggest change in temperature between successive depth readings and report the depths above and below that interval.

For example, given the following set of readings, the largest change in temperature occurs between 23.98 and 25.61 meters, so those would be the depths reported. If there is more than one occurrence of the same largest change, reported the shallowest pair.

depth

temperature

31.53

7.25

30.03

7.83

28.52

7.97

27.02

8.32

25.61

8.51

23.98

12.33

22.51

13.14

21.07

13.18

19.52

13.18

18.20

13.19

16.53

13.19

6. Define the following triggers. Treat each separately, that is, don't assume that the triggers from earlier parts are in place when you answer later ones.

(a) When the last reading in a profile is deleted, also delete the profile.

(b) Readings should not be taken at a depth that exceeds the water depth at the site. Signal an error (and do not allow the modification) if this occurs.

(c) If a reading is inserted without a timestamp, use the timestamp from the reading's profile.

Questions 7-14 make use of the following relational schema for a flight reservation database.

FLIGHT(fliohtnum, from, to, miles, deptime, arrtime)

FARE(farecode, price)

PRICING(flightnum, farecode, numseats)

RESERVATION(name, flightnum, date, farecode, confnum)

AIRPORT(code, city, state)

'state' is the two-letter state abbreviation e.g. NY. Departure and arrival times use the 24-hour clock. Key attributes are underlined. Foreign key constraints:

  • FLIGHT. from and FLIGHT. to refer to AIRPORT. code
  • PRICING . flightnum and RESERVATION. flightnum refer to FLIGHT. flightnum
  • PRICING. farecode and RESERVATION. farecode refer to FARE. farecode

Write an SQL query for each of the following. You can use the database ex_flights if you want to test your queries.

7. Find the flights departing from an airport in NY state.

8. Find the names of passengers who have more than one reservation.

9. Find the flights which have at least one seat in every fare code.

10. Find the flights with no reservations.

11. Find the total number of seats on each flight.

12. Find the cheapest fare that has been booked on each flight, along with the fare code and the names of the people who have booked that fare.

13. For each flight and fare code, determine the number of seats available. (The number of seats available is the number of seats allocated for the flight and fare code minus the number that have been reserved.)

14. Find all of the airports that can be reached from ROC with exactly one stop. Make sure that the connection is legal - the second flight cannot depart before the first one arrives. For example, one such airport is LAX because there's a flight ROC→ORD which arrives at 6:59 and a flight ORD-) LAX which leaves at 8:32.

Bonus - Write an SQL statement/query for each of the following. (use the flight reservations database schema)

15. For each airport, find the number of passengers who have a reservation departing from that airport and the total ticket sales for those flying first class (fare codes starting with 'F', 'A', or 'P').

16. Find the busiest airport(s) - the one(s) with the largest number of departing and arriving flights. (Include all such airports if there's a tie.)

17. For each flight, find the top three fare codes in terms of the revenues brought in. The revenue brought in for a fare code is the number of reservations at that fare code times the price of that fare code.

You may use the textbook on reserve in the library (Elmasri and Navathe, 5th edition), your own course materials (your own assignments that have been handed back and notes made prior to the exam being handed out), and the materials posted directly on the course website.

DBMS, Programming

  • Category:- DBMS
  • Reference No.:- M92517168
  • Price:- $65

Guranteed 36 Hours Delivery, In Price:- $65

Have any Question?


Related Questions in DBMS

Assignment question - write and run sql statements to

Assignment Question - Write and run SQL statements to complete the following tasks Part A - DML 1. Locate the record in the vendor table that does not have a value for the attribute V_STATE 2. Find the customers whose ba ...

In sql developer onlydeliverables include sql scripts and

In SQL Developer ONLY! Deliverables Include SQL scripts and screenshot of the results: D1. Create the following three user-defined roles that are shown in the table below and assign them the specified permissions for the ...

In this section the student is required to develop a

In this section, the student is required to develop a technical debate based on his/her understanding using available scientific literature. The answer to this question should not exceed three A4 Pages. In the traditiona ...

Sql query assignment -for this assignment you are to write

SQL Query Assignment - For this assignment you are to write your answers in a word document. This assignment is in three parts: Part A (reporting queries), Part B (query performance), Part C (query design). For this assi ...

We can represent a data set as a collection of object nodes

We can represent a data set as a collection of object nodes and a collection of attribute nodes, where there is a link between each object and each attribute, and where the weight of that link is the value of the object ...

Sql transactions exercisesconsider table itemnameprice

SQL Transactions Exercises Consider table Item(name,price) where name is a key, and the following two concurrent transactions. T1: Begin Transaction; Update Item Set price = 2*price Where name = 'pencil'; Insert Into Ite ...

Questionsuppose a prolog database exists that gives

Question: Suppose a Prolog database exists that gives information about states and capital cities. Some cities are big, others small. Some states are eastern, others are western. a. Write a query to find all the small ca ...

Question as explained throughout this course entity

Question: As explained throughout this course, entity relationship modeling is a critical element of database design. If the database is not properly modeled, it is unlikely that the database will be properly developed. ...

Database design and development assignment -assessment task

Database Design and Development Assignment - Assessment task - 1. Normalization a) Map the ERD, from the sample solution, into a set of relations in at least Third Normal Form (3NF). You must ensure that your relations m ...

Solve the following questions using oracle you are not

Solve the following questions using Oracle. You are not allowed to use the syntax of any DBMS other than Oracle. Make sure to upload an electronic copy of your solution to your CSC335 TRACE folder. Name the file hw4.sql. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As