Files
G4G0-1/Semester 1/DatabaseBackup/Week 5/Week 5 Database Systems.md
2024-01-15 20:14:10 +00:00

3.2 KiB
Raw Blame History

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

  • Many different notations
  • One is "crows foot":

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.
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.
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”.
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.
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.
INSERT INTO atm 
VALUES ("atm05", "high", "0", "T1");
  1. Add an attribute called telephone number to the relation Branch.
ALTER TABLE branch
ADD telephone CHAR(15)
  1. Set the address of every branch to the value Salford.
UPDATE branch
SET address = "Salford";
  1. Bank LEFT OUTER JOIN Branch
SELECT *
FROM bank
INNER JOIN