lint all files

This commit is contained in:
2024-01-16 13:48:46 +00:00
parent b515ba4458
commit a321b0ce99
45 changed files with 66985 additions and 23206 deletions

View File

@@ -14,7 +14,7 @@ CREATE TABLE hospital (
);
```
2. **transplant_unit** Table
1. **transplant_unit** Table
Attributes:
`unit_id` (Primary Key)
`hospital_id` (Foreign Key referencing Hospital)
@@ -28,7 +28,7 @@ CREATE TABLE transplant_unit (
);
```
3. **organ** Table:
1. **organ** Table:
Attributes:
`organ_id` (Primary Key)
`organ_type`
@@ -40,7 +40,7 @@ CREATE TABLE organ (
);
```
4. **patient** Table:
1. **patient** Table:
Attributes:
`patient_id` (Primary Key)
`patient_name`
@@ -54,11 +54,11 @@ CREATE TABLE patient (
);
```
5. **donor** Table:
1. **donor** Table:
Attributes:
`donor_id` (Primary Key)
`donor_name`
`age`
`age`
```SQL
CREATE TABLE donor (
@@ -68,7 +68,7 @@ CREATE TABLE donor (
);
```
6. **operation** Table
1. **operation** Table
Attributes:
`operation_id` (Primary Key)
`unit_id` (Foreign Key referencing TransplantUnit)
@@ -85,4 +85,4 @@ CREATE TABLE operation (
donor_id CHAR(3) CONSTRAINT dID_fk FOREIGN KEY REFERENCES donor( donor_id ),
CONSTRAINT comp_op_key PRIMARY KEY ( operation_id, organ_id )
);
```
```

View File

@@ -12,7 +12,7 @@ A unit has 1 specialisation
4. A unit can transplant the other types of organ which lie outside of its area of expertise.
A unit does not specifically have to transplant it's specialisation
5. Some hospitals host more than one transplant unit.
5. Some hospitals host more than one transplant unit.
However some do not have a transplant unit.
A hospital can have 0, 1 or many transplant units.

View File

@@ -13,12 +13,12 @@ VALUES ('h01', 'Royal Infirmary', 'Manchester', 'M13 1AB'),
('h04', 'Wythenshawe Hospital', 'Manchester', 'M22 4XD');
```
2. **transplant_unit** Table
1. **transplant_unit** Table
Attributes:
`unit_id` (Primary Key)
`hospital_id` (Foreign Key referencing Hospital)
`specialisation`
```SQL
INSERT INTO transplant_unit
VALUES ( 'u001', 'h01', 'Kidney (Renal)' ),
@@ -28,7 +28,7 @@ VALUES ( 'u001', 'h01', 'Kidney (Renal)' ),
( 'u005', 'h04', 'Cardiothoracic' );
```
3. **organ** Table:
1. **organ** Table:
Attributes:
`organ_id` (Primary Key)
`organ_type`
@@ -42,7 +42,7 @@ VALUES ( 'o1', 'kidney' ),
( 'o5', 'liver' );
```
4. **patient** Table:
1. **patient** Table:
Attributes:
`patient_id` (Primary Key)
`patient_name`
@@ -55,7 +55,7 @@ VALUES ( 'p03', 'ben', 58 ),
( 'p05', 'joan', 50);
```
5. **donor** Table:
1. **donor** Table:
Attributes:
`donor_id` (Primary Key)
`donor_name`
@@ -71,7 +71,7 @@ VALUES ( 'd01', 'tom', 34 ),
( 'd06', 'rose', 34 );
```
6. **operation** Table
1. **operation** Table
Attributes:
`operation_id` (Primary Key)
`unit_id` (Foreign Key referencing TransplantUnit)
@@ -87,4 +87,4 @@ VALUES ( 'op1', 'o1', 'u002', 'p03', 'd01' ),
( 'op3', 'o4', 'u003', 'p05', 'd03' ),
( 'op4', 'o5', 'u004', 'p05', 'd05' ),
( 'op5', 'o5', 'u002', 'p03', 'd01' );
```
```

View File

@@ -1,4 +1,4 @@
3. List the names of patients who are at least fifty years old. Your query should always generate a list in which the names are sorted in alphabetical order. The ordering must not depend upon the order in which you entered data into your database.
1. List the names of patients who are at least fifty years old. Your query should always generate a list in which the names are sorted in alphabetical order. The ordering must not depend upon the order in which you entered data into your database.
```SQL
SELECT patient_name
@@ -9,7 +9,7 @@ ORDER BY patient_name;
![](Pasted%20image%2020231204184010.png)
4. List the name of each type of organ, together with the total number of donations of that type of organ.
1. List the name of each type of organ, together with the total number of donations of that type of organ.
```SQL
SELECT organ_type, COUNT( organ_type )
@@ -20,7 +20,7 @@ GROUP BY organ_type;
![](Pasted%20image%2020231204184814.png)
5. List the identifiers of hospitals where a transplant has been performed, together with the number of transplant operations at the hospital.
1. List the identifiers of hospitals where a transplant has been performed, together with the number of transplant operations at the hospital.
```SQL
SELECT hospital_id, COUNT( hospital_id )
@@ -31,7 +31,7 @@ GROUP BY hospital_id;
![](Pasted%20image%2020231204191255.png)
6. Output the age of the oldest person who has donated in a hospital in Manchester.
1. Output the age of the oldest person who has donated in a hospital in Manchester.
```SQL
SELECT age
@@ -49,4 +49,4 @@ WHERE donor_id IN (
)
)
);
```
```

View File

@@ -9,7 +9,7 @@ Attributes:
The Hospital table is in 1NF as values would be atomic with no repeating groups. It is in 2NF as all attributes are dependent on the primary key with no partial dependencies, and it is in 3NF as there are no transitive dependencies; all attributes exclusively depend on the primary key.
2. **TransplantUnit** Table:
1. **TransplantUnit** Table:
Attributes:
`UnitID` (Primary Key)
@@ -18,7 +18,7 @@ Attributes:
The TransplantUnit table is in 1NF as values would be atomic with no repeating groups. It is in 2NF as all attributes are dependent on the primary key with no partial dependencies, and it is in 3NF as there are no transitive dependencies; all attributes exclusively depend on the primary key.
3. **Organ** Table:
1. **Organ** Table:
Attributes:
`OrganID` (Primary Key)
@@ -26,7 +26,7 @@ Attributes:
The OrganType table is in 1NF as values would be atomic with no repeating groups. It is in 2NF as all attributes are dependent on the primary key with no partial dependencies, and it is in 3NF as there are no transitive dependencies; all attributes exclusively depend on the primary key.
4. **Donor** Table:
1. **Donor** Table:
Attributes:
`DonorID` (Primary Key)
@@ -34,7 +34,7 @@ Attributes:
`Age`
The Donor table is in 1NF as values would be atomic with no repeating groups. It is in 2NF as all attributes are dependent on the primary key with no partial dependencies, and it is in 3NF as there are no transitive dependencies; all attributes exclusively depend on the primary key.
5. **Patient** Table:
1. **Patient** Table:
Attributes:
`PatientID` (Primary Key)
@@ -43,7 +43,7 @@ Attributes:
The Patient table is in 1NF as values would be atomic with no repeating groups. It is in 2NF as all attributes are dependent on the primary key with no partial dependencies, and it is in 3NF as there are no transitive dependencies; all attributes exclusively depend on the primary key.
6. **Operation** Table:
1. **Operation** Table:
We need an Operations table to record / capture information related to the operations themselves. This should include an ID for the operation as a primary key, the ID of the unit it was conducted in, the ID of the organ type used, the ID of the donor and the ID of the patient. This allows us to establish proper relationships to the other tables, and allows for a comprehensive record of the transplant process.
This table also allows us to query easier, since all queries can be done on the one table to find essentially any information.

View File

@@ -1,4 +1,5 @@
1. **Hospital** Table
```SQL
CREATE TABLE hospital (
hospital_id CHAR(3) CONSTRAINT hID_pk PRIMARY KEY,
@@ -9,6 +10,7 @@ CREATE TABLE hospital (
```
2. **Transplant_Unit** Table
```SQL
CREATE TABLE transplant_unit (
unit_id CHAR(4) CONSTRAINT uID_pk PRIMARY KEY,
@@ -20,6 +22,7 @@ CREATE TABLE transplant_unit (
```
3. **Organ** Table:
```SQL
CREATE TABLE organ (
organ_id CHAR(3) CONSTRAINT oID_pk PRIMARY KEY,
@@ -28,6 +31,7 @@ CREATE TABLE organ (
```
4. **Patient** Table:
```SQL
CREATE TABLE patient (
patient_id CHAR(3) CONSTRAINT pID_pk PRIMARY KEY,
@@ -37,6 +41,7 @@ CREATE TABLE patient (
```
5. **Donor** Table:
```SQL
CREATE TABLE donor (
donor_id CHAR(3) CONSTRAINT dID_pk PRIMARY KEY,
@@ -46,6 +51,7 @@ CREATE TABLE donor (
```
6. **Operation** Table
```SQL
CREATE TABLE operation (
operation_id CHAR(3),
@@ -60,4 +66,4 @@ CREATE TABLE operation (
CONSTRAINT pID_fk FOREIGN KEY ( patient_id ) REFERENCES patient( patient_id ),
CONSTRAINT dID_fk FOREIGN KEY ( donor_id ) REFERENCES donor( donor_id )
);
```
```

View File

@@ -169,6 +169,7 @@ SELECT origin FROM pirates;
## Workshop 1 (10:00)
- Implement the two tables using the SQL CREATE TABLE command.
```sql
CREATE TABLE employee(
empNo INTEGER PRIMARY KEY
@@ -204,4 +205,4 @@ SELECT empNo, eName
FROM employee
INNER JOIN manager
ON employee.empNo = manager.empNo;
```
```

View File

@@ -28,4 +28,4 @@ Challenge Question
There are just five orders in which both the customer and employee come from the same
city. These five orders involve just two cities. Write an SQL query which lists the names
of these cities.
![](Pasted%20image%2020230929095251.png)
![](Pasted%20image%2020230929095251.png)

View File

@@ -75,7 +75,7 @@ WHERE security-level = "normal"
ORDER BY age DESC;
```
2. List the name of each bank which has a branch whose address starts with the word Eccles. The list should not include any duplicates.
1. List the name of each bank which has a branch whose address starts with the word Eccles. The list should not include any duplicates.
```sql
SELECT DISTINCT name
@@ -84,7 +84,7 @@ WHERE Bank.bankID = Branch.bankID
AND address LIKE "Eccles*";
```
3. Calculate the average age of the ATMs with low or normal levels of security. Name the results column “Average age”.
1. Calculate the average age of the ATMs with low or normal levels of security. Name the results column “Average age”.
```sql
SELECT AVG(age) AS "Average Age"
@@ -92,37 +92,38 @@ FROM atm
WHERE security-level = "low" OR security-level = "normal";
```
4. Remove the tuple from the relation ATM whose identifier is atm04.
1. Remove the tuple from the relation ATM whose identifier is atm04.
```sql
DELETE FROM atm
WHERE atmID = "atm04";
```
5. Add a row for an ATM, whose atmID is atm05, whose security level is high and which is located at branch T1.
1. Add a row for an ATM, whose atmID is atm05, whose security level is high and which is located at branch T1.
```sql
INSERT INTO atm
VALUES ("atm05", "high", "0", "T1");
```
6. Add an attribute called telephone number to the relation Branch.
1. Add an attribute called telephone number to the relation Branch.
```sql
ALTER TABLE branch
ADD telephone CHAR(15)
```
7. Set the address of every branch to the value Salford.
1. Set the address of every branch to the value Salford.
```sql
UPDATE branch
SET address = "Salford";
```
1) Bank LEFT OUTER JOIN Branch
1. Bank LEFT OUTER JOIN Branch
```sql
SELECT *
FROM bank
INNER JOIN
```
```

View File

@@ -148,6 +148,7 @@ A car must have exactly one owner.
### Exercise 1
#### Part 1
Project -o---|-/\\- Order
\[1:M] \[o:m] Relationship
@@ -155,6 +156,7 @@ project(proj#, name, start-date, end-date)
order(order#, date, inquiry, proj#\*)
#### Part 2
Supplier -/\\-o---o-/\\- Part
\[M:M] \[o:o] Relationship
@@ -165,6 +167,7 @@ orderList(supplier#\*, part#\*)
- We must create a new composite table to contain the relation, since we cannot sustain the principles of foreign keys.
#### Part 3
Staff -/\\-|---|- Department
\[M:1] \[m:m] Relationship
@@ -174,6 +177,7 @@ department(dept-id, name, location)
- We would create dept-id as a foreign key in the staff table, as multiple values wont occur, and staff must be a part of a department in this scenario.
#### Part 4
Manager -|---|- Project
\[1:1] \[m:m] Relationship
@@ -183,6 +187,7 @@ project(proj-id, name, start-date, end-date)
- We could use either primary key for the alternate table's foreign key, since they are both mandatory and 1:1, so there would be no multiple values nor would there be null values.
#### Part 5
Manager -|---|-/\\- Team -|---|-/\\- Player
\[1:M] \[m:m] (Both) Relationship
@@ -193,14 +198,16 @@ player(player-id, name, address, tel-no, team-name*)
## Tutorial 2 (14:00)
#### Entities & Attributes
| Entities | Attributes |
|----------|------------|
| Regional Office | *regioncode*, name, location |
| Regional Office | *regioncode*, name, location |
| Branch | *branch_no*, institution |
| Member | *mem_no*, name, age, type |
| Role | *role_id*, level, role |
| Role | *role_id*, level, role |
#### Relations
Role - \[1:M]\[m:o] - Member
Member - \[M:1]\[o:m] - Branch
Member - \[M:1]\[o:m] - Branch
Branch - \[M:1]\[m:m] - Region

View File

@@ -92,4 +92,4 @@ WHERE value > (
3. List names of the products whose number of units in stock is less than the average number of units in stock and whose number of units on order is less than the average number of units on order.
![](Pasted%20image%2020231110104639.png)
![](Pasted%20image%2020231110104639.png)