Files
G4G0-1/Semester 1/Database Systems/Week 5/Week 5 Database Systems.md
2024-01-16 13:48:46 +00:00

130 lines
3.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## Lecture 1 (13:00) - Conceptual Modelling
### Role of Conceptual Modelling
- Real world problem -> Conceptual Model Data -> Logical Data Model -> Physical Model (DBMS)
- Identify important concepts and data needs, creating a conceptual model.
- Many different ways to get to the same solution.
- Iterative process - if one method does not work, it can be revised.
### Conceptual Data Model
- Abstract view of situation.
- Identifies important elements and relationships between them. (ex. Library: Books, Members, ~~Carpets~~)
- Human interact-able, not computer terms.
- Implementation Independent.
- Useful for client brief.
### Reasons for Using ER Modelling
- Simpler and easier to understand than database tables
- Helps discussions with clients and colleagues
- Allows for segmentation of work.
- Modelling real world solution
- Designing DB tables
- Most large organisations will require it
### Obtaining an ER Model
- Given a spec, you need to identify:
- entities - 'things' with physical or conceptual existence
- relationships
- attributes
- constraints or assumptions
#### Example
Departments control many projects and each department has many employees. Each employee works on only one project at a time. A projects start date must be before the projects target completion date. Each employee has an NI number, name and address
Entities:
- departments
- projects
- employees
Relationships:
- **control** between departments and projects
- **has between** departments and employees
- **works on** between employees and projects
Attributes:
- startdate
- completiondate
- ninumber
- name
- address
Constraints:
- Start date must be before the target completion date
### ER Diagram
![](Pasted%20image%2020231017132317.png)
- Many different notations
- One is "crows foot":
![](Pasted%20image%2020231017132357.png)
![](Pasted%20image%2020231017133438.png)
![](Pasted%20image%2020231017133451.png)
## Lecture 3 (16:00)
1. Generate a list of the ages of ATMs whose security level is normal. The list should be in descending order.
```sql
SELECT age
FROM atm
WHERE security-level = "normal"
ORDER BY age DESC;
```
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
FROM bank, branch
WHERE Bank.bankID = Branch.bankID
AND address LIKE "Eccles*";
```
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"
FROM atm
WHERE security-level = "low" OR security-level = "normal";
```
1. Remove the tuple from the relation ATM whose identifier is atm04.
```sql
DELETE FROM atm
WHERE atmID = "atm04";
```
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");
```
1. Add an attribute called telephone number to the relation Branch.
```sql
ALTER TABLE branch
ADD telephone CHAR(15)
```
1. Set the address of every branch to the value Salford.
```sql
UPDATE branch
SET address = "Salford";
```
1. Bank LEFT OUTER JOIN Branch
```sql
SELECT *
FROM bank
INNER JOIN
```