Create and query databases using SQL
Task
Part A - SQL Queries
Use the hospital database (hosp2010.sql) from the Interact Resources site. Answer the following queries from that database.
You are required to submit:
1. The appropriate SQL statements for each query, which should be copied from your SQL code in MySQL and pasted into your submission file
2. Screenshots of the resultant tables which are to be pasted into your submission file immediately after the SQL code for that query.
Typing or manually drawing the results is NOT acceptable.
Question 1
Find out what actual operations were performed by the surgeon 103. List the surgeon code, the code of the actual operation and the date the operation was performed. Show the operation date by the day of the week, the day of the month, the month and the year (ie: Tuesday, 7 October, 2014). Sort the list in most recent date of operation.
Question 2
Find out which patients have not been discharged yet, listing their last name and the date they were admitted. Show the admission date by the day of the month, month and the full year (ie: 6/12/2001).
Question 3
List all the persons who were admitted to the Flemming Ward prior to 1995. Show the persons first and last name, ward name and the date of their admission. Show the admission date by the day of the month, month and the full year (ie: 6/12/2001).
Question 4
For the patients who have been discharged, show the number of days that they stayed at a ward. Also show the patients ID and last name, ward code and the date of admission. Show the admission date by the day of the week, the day of the month, the month and the year (ie: Tuesday, 7 October, 2014). Sort the list in most recent date of admission.
Question 5
A. List the first name and surname of male patients from NSW or ACT (i.e. the postcode is in the 2000's), who have had an operation and recovered in either the Pasteur or the Fleming ward. Mention them only once if they recovered in the same ward more than once. (4 marks)
B. After executing your query, explain the logic of your SQL statement/s (for example, why/how you joined tables and for what reason, etc.), and do this for each part of this query.
Part B - DDL
Question 1
Add a new attribute (field) ‘FullName' to the STAFF table with appropriate data type and realistic number of characters.
Question 2
Add the following staff names into the new field you have added above:
103 Dean Matthews
114 Ray Bones
115 Francess Martinez
116 Tammy Son
Question 3
Delete the Nurse Francess Martinez from the staff table
Question 4
Write the SQL DDL to create the database that contains each of the relations shown in the ERD below:
Make sure to add the necessary data type and size for each of the attributes used.
You will need to provide:
• Your DDL code for each table that you create;
• A screenshot showing each table that is created.