Presentation is loading. Please wait.

Presentation is loading. Please wait.

Topic 3: Data Databases.

Similar presentations


Presentation on theme: "Topic 3: Data Databases."— Presentation transcript:

1 Topic 3: Data Databases

2 Storing Data When it comes to storing data, we have different ways of storing it Each way of storage is thought of as a different structure of data These different structures include Saving pure text files with paragraphs of information Storing data in an XML (Extensible Markup Language) file Keeping data in a series of tables Data: Databases

3 Storing Data These different structures have specific names
Unstructured When we save data with no structure at all Like paragraphs in a text file Makes finding information inside difficult (as we have to read everything) Data: Databases

4 Storing Data Semi-Structured
When our data has some structure, but is still difficult to read/understand Most commonly seen in markup languages Like HTML or XML We still follow some structure, but we still have freedom to change this structure as needed Structured When our data has a very rigid and defined structure (that we can’t easily change) Commonly seen when storing data in tables (with rows and columns) Makes it very easy to find something (as we find the row/column we need) Data: Databases

5 Data Models Databases are used whenever we want to store lots of structured data Literally the base of our data Can come in lots of different formats (each one changing how we use it) Relational Factual Flat-format We will be looking at relational databases Data: Databases

6 Data Models Before creating any data, or any structures for the data, we first analyse the requirements of the database This comes into play in two ways The data requirements What data do things need in total For example, a classroom needs a classroom code, year group, and teacher The data constraints What can the data not do, or not be grouped with For example, a classroom cannot have more than one teacher Data: Databases

7 Data Models Relational databases work based off of two things
The entities that the database contains The relationship between these entities These types of databases are designed to accurately reflect the world By identifying relationships between entities We can use these to plan out a Conceptual Data Model of the database Entity A single place, person, or thing about which data can be stored Data: Databases

8 Data Models Each entity can also have data associated with them
Each piece of data fitting into a property, also known as an attribute For example, a Person entity might have the following attributes Name Age Gender Databases contain many records of an entity for each individual person/place/thing Each record is known as an instance, or occurrence Data: Databases

9 Student(FirstName, Surname, DateOfBirth, CurrentFormGroup)
Data Models We can write entities out, with their attributes, in a simple description For example, a Student has a First Name, Surname, Date of Birth, and Current Form Group We can describe this entity using the following: Student(FirstName, Surname, DateOfBirth, CurrentFormGroup) Data: Databases

10 Student(FirstName, Surname, DateOfBirth, CurrentFormGroup)
Data Models All entities need one attribute (or a combination of them) the uniquely identify them This is known as the Entity Identifier We can either add an attribute specifically for this (like an ID), or use a combination of attributes (like a first and last name) Note that entity identifiers should be unique among all entities of one type Here’s an example (the underlined attributes combine to make the entity identifier) Student(FirstName, Surname, DateOfBirth, CurrentFormGroup) Data: Databases

11 Student(FirstName, Surname, DateOfBirth, CurrentFormGroup)
Data Models The individual attributes on their own would be too weak to use as an identifier As there could by many students with the same first name However, lots of them combined are more appropriate As the chance of finding a student with all three being the same are negligible Student(FirstName, Surname, DateOfBirth, CurrentFormGroup) Data: Databases

12 Create a data model for the following situation, and write the entity descriptions the model would use: A system administrator is creating a database for a university. They need to store information about the modules they offer, the professors that teach those modules, and the students that enrol onto those modules. Module have their module ID, their name, and branching subject (like Maths, Computer Science, Art, and so on). Professors have their name and faculty ID. Students have their name, date of birth, course enrolment (like Microbiology, Computer Science and Maths, Software Engineering) and module enrolment. Data: Databases

13 Data Models We can represent entities (and their attributes) in a visual format Each rectangle is an entity, and the lines inside them are their attributes Where the entity identifier is underlined Can be referred to as an entity diagram Data: Databases

14 For the data model you made in the previous exercise
Create an entity diagram for each entity Remember to underline the entity identifier for that entity Data: Databases

15 Entity Relationships A relationship is an association between two entities Like a House and a Person A House could contain multiple People Relationships have degrees (known as cardinalities), defining the maximum number of entities one entity can be linked to One-to-One One-to-Many Many-to-Many Data: Databases

16 Entity Relationships Here are some examples of cardinalities in action
Primary care physicians will help many patients One-to-Many Surgeons perform operations Many-to-Many Patients have health-care cards One-to-One Data: Databases

17 For your data model from before, think about what relationships it would use
And the cardinalities of them A system administrator is creating a database for a university. They need to store information about the modules they offer, the professors that teach those modules, and the students that enrol onto those modules. Module have their module ID, their name, and branching subject (like Maths, Computer Science, Art, and so on). Professors have their name and faculty ID. Students have their name, date of birth, course enrolment (like Microbiology, Computer Science and Maths, Software Engineering) and module enrolment. Data: Databases

18 Entity Relationships We can represent relationships between entities in a visual format Making use of entity diagrams Data: Databases

19 Entity Relationships These lines have specific start and end points
Each representing a different cardinality Data: Databases

20 Entity Relationships We can flesh out the relationship diagram with entity diagrams to create the full Entity Relationship (ER) Diagram Data: Databases

21 Create an ER Diagram using the data model, entity descriptions, and relationships you made for this situation A system administrator is creating a database for a university. They need to store information about the modules they offer, the professors that teach those modules, and the students that enrol onto those modules. Module have their module ID, their name, and branching subject (like Maths, Computer Science, Art, and so on). Professors have their name and faculty ID. Students have their name, date of birth, course enrolment (like Microbiology, Computer Science and Maths, Software Engineering) and module enrolment. Data: Databases

22 Relational Data Models
These kinds of models are based on mathematics Using the idea of a relation For example, we have two sets 𝑇𝑒𝑎𝑐ℎ𝑖𝑛𝑔𝑆𝑡𝑎𝑓𝑓={𝑀𝑟 𝐴, 𝑀𝑟𝑠 𝐵, 𝑀𝑟 𝐶} 𝑀𝑜𝑑𝑢𝑙𝑒𝑠={𝑃𝑟𝑜𝑔𝑟𝑎𝑚𝑚𝑖𝑛𝑔 101, 𝐿𝑖𝑛𝑒𝑎𝑟 𝐴𝑙𝑔𝑒𝑏𝑟𝑎, 𝐺𝑒𝑛𝑒𝑡𝑖𝑐 𝐶𝑜𝑚𝑝𝑢𝑡𝑖𝑛𝑔} We can form a relation of these (creating their own set) 𝐴𝑠𝑠𝑖𝑔𝑛𝑇𝑒𝑎𝑐ℎ𝑒𝑟𝑠= 𝑀𝑟 𝐴, 𝐿𝑖𝑛𝑒𝑎𝑟 𝐴𝑙𝑔𝑒𝑏𝑟𝑎 , 𝑀𝑟𝑠 𝐵, 𝐺𝑒𝑛𝑒𝑡𝑖𝑐 𝐶𝑜𝑚𝑝𝑢𝑡𝑖𝑛𝑔 , 𝑀𝑟 𝐶, 𝑃𝑟𝑜𝑔𝑟𝑎𝑚𝑚𝑖𝑛𝑔 101 Data: Databases

23 Relational Data Models
In these models, we would represent entities as tables Every column in the table being an attribute of that entity Every row in the table being an instance/occurrence of that entity The underlined column is the entity identifier ModuleCode ModuleName TotalCredits NumberOfLessons HoursPerLesson PRO101 Programming 101 10 12 1 LIN001 Linear Algebra GEN001 Genetic Computing 20 24 2 Data: Databases

24 Based off this relational data model for a Module table
Come up with a relational data model for a Teacher table Should include the teacher’s ID, name, start date, and assigned modules Come up with at least three occurrences to put in the table ModuleCode ModuleName TotalCredits NumberOfLessons HoursPerLesson PRO101 Programming 101 10 12 1 LIN001 Linear Algebra GEN001 Genetic Computing 20 24 2 Data: Databases

25 Relational Data Models
You may have come up with something like this for the Teacher table With both of these tables together, we have an implicit relation As the Teacher table refers to AssignedModules Which are the ModuleCode values from the Module table ID FirstName LastName StartDate AssignedModules Johnathan Joseph 02/04/1999 PRO101, MAL002 Abi Pranav 16/06/2010 LIN001, ALG001 Clive Sinclair 21/03/1990 GEN001 Data: Databases

26 Relational Data Models
We have to link data from one table to another to create a relation The type of relation depends on where and how the values are used The entity identifier is referred to as the Primary Key (when in its own table) When this is used in another table, we call it the Foreign Key In our example earlier, the AssignedModules is the Foreign Key for the ModuleCode Data: Databases

27


Download ppt "Topic 3: Data Databases."

Similar presentations


Ads by Google