SlideShare uma empresa Scribd logo
1 de 24
Databases

Creating Relational Databases
School Database
Student ID Student   Student     Form   Sex   Age   Class      Class     Room
           Surname   FirstName                      Name       Teacher   Number
S10204     HALL      Taighan     10B    F     13    Maths101   PRJ       651
S10204     HALL      Taighan     10B    M     13    GEO101     RW        532
S10204     HALL      Taighan     10B    F     13    SCI10      CW        161
S10412     CRIST     Graeme      10D    M     14    GEO101     RW        532
S10412     CRIST     Graeme      10D    M     14    HIS101     HJD       541
S10101    CRIST     Graeme      10D    M     14    Maths101   PRJ       651
S10414     HASLETT   Oliver      10D    M     14    Maths101   PRJ       651
S10101     FUNG      JUNE        10A   F     15    Maths101   PRJ       651
S10101     FUNG      JUNE        10B   F     15    GEO101     HJD       532
S10101     FUNF     JUNE        10A    F     15    HIS101     HJD       541


This is part of a database showing all students and
their classes in a school.
Data integrity and Data Redundancy
These issues can have a significant impact on
the ability for a database to actually do the
job that it is intended to do.

Data Integrity is the idea that information
always keeps its meaning. This is particularly
difficult when databases get really big. If you
imagine the database above includes every
student and every class in the school it could
contain over 10000 records.
School Database
Student ID Student    Student     Form     Sex        Age       Class      Class     Room
           Surname    FirstName                                 Name       Teacher   Number
S10204     HALL       Taighan     10B      F          13        Maths101   PRJ       651
S10204     HALL       Taighan     10B      M          13        GEO101     RW        532
S10204     HALL       Taighan     10B      F          13        SCI10      CW        161
S10412     CRIST      Graeme      10D      M          14        GEO101     RW        532
S10412     CRIST      Graeme      10D      M          14        HIS101     HJD       541
S10101    CRIST      Graeme      10D      M          14        Maths101   PRJ       651
S10414     HASLETT    Oliver      10D      M          14        Maths101   PRJ       651
S10101     FUNG       JUNE        10A     F          15        Maths101   PRJ       651
S10101     FUNG       JUNE        10B     F          15        GEO101     HJD       532
S10101     FUNF      JUNE        10A      F          15        HIS101     HJD       541




           This is part of a database showing all students and their classes in a school.
Examples of Data integrity
Examples of Data integrity

  A simple typo means that it might mean
that information gets lost if we search for June
in the data. This problem is much more likely
because of the redundancies issues we will look
at later.
School Database
Student ID Student    Student     Form     Sex        Age       Class      Class     Room
           Surname    FirstName                                 Name       Teacher   Number
S10204     HALL       Taighan     10B      F          13        Maths101   PRJ       651
S10204     HALL       Taighan     10B      M          13        GEO101     RW        532
S10204     HALL       Taighan     10B      F          13        SCI10      CW        161
S10412     CRIST      Graeme      10D      M          14        GEO101     RW        532
S10412     CRIST      Graeme      10D      M          14        HIS101     HJD       541
S10101    CRIST      Graeme      10D      M          14        Maths101   PRJ       651
S10414     HASLETT    Oliver      10D      M          14        Maths101   PRJ       651
S10101     FUNG       JUNE        10A     F          15        Maths101   PRJ       651
S10101     FUNG       JUNE        10B     F          15        GEO101     HJD       532
S10101     FUNF      JUNE        10A      F          15        HIS101     HJD       541




           This is part of a database showing all students and their classes in a school.
Examples of Data integrity
Examples of Data integrity

 This example can cause real problems it
shows that the same information in the
database can mean two different things is
s10101 Graeme or June.
School Database
Student ID Student    Student     Form     Sex        Age       Class      Class     Room
           Surname    FirstName                                 Name       Teacher   Number
S10204     HALL       Taighan     10B      F          13        Maths101   PRJ       651
S10204     HALL       Taighan     10B      M          13        GEO101     RW        532
S10204     HALL       Taighan     10B      F          13        SCI10      CW        161
S10412     CRIST      Graeme      10D      M          14        GEO101     RW        532
S10412     CRIST      Graeme      10D      M          14        HIS101     HJD       541
S10101    CRIST      Graeme      10D      M          14        Maths101   PRJ       651
S10414     HASLETT    Oliver      10D      M          14        Maths101   PRJ       651
S10101     FUNG       JUNE        10A     F          15        Maths101   PRJ       651
S10101     FUNG       JUNE        10B     F          15        GEO101     HJD       532
S10101     FUNF      JUNE        10A      F          15        HIS101     HJD       541




           This is part of a database showing all students and their classes in a school.
Examples of Data integrity
Examples of Data integrity

 Here we have June in two classes? Which
one is right? What if we need to find June in
registration urgently
Hard to find?
They can be really hard to find in this Database
there are more integrity errors can you find
them?
Student ID Student   Student     Form   Sex   Age   Class      Class     Room
           Surname   FirstName                      Name       Teacher   Number


S10204     HALL      Taighan     10B    F     13    Maths101   PRJ       651

S10204     HALL      Taighan     10B    M     13    GEO101     RW        532

S10204     HALL      Taighan     10B    F     13    SCI10      CW        161

S10412     CRIST     Graeme      10D    M     14    GEO101     RW        532

S10412     CRIST     Graeme      10D    M     14    HIS101     HJD       541

S10101    CRIST     Graeme      10D    M     14    Maths101   PRJ       651


S10414     HASLETT   Oliver      10D    M     14    Maths101   PRJ       651

S10101     FUNG      JUNE        10A   F     15    Maths101   PRJ       651

S10101     FUNG      JUNE        10B   F     15    GEO101     HJD       532

S10101     FUNF     JUNE        10A    F     15    HIS101     HJD       541
Bad or unnecessary Fields Names
Age is an example of a bad field name for the
obvious reason that it can change at anytime.
It would be much better to use DOB as age
can always be calculated and ofcourse it does
not change.

Form may also be unnecessary in this case as
the reference number is CODED to give the
form.

Can you explain the code?
Data Redundancy
Data redundancy is the where data needs to be
entered and stored on more than one occasion.

For example if you look at the table you can see
that we have entered Oliver Haslett’s first name
and surname every time we put him into a
class. This can cause problems such as
increasing the chance of someone entering his
name wrong. It also means more time is
needed to enter data and more space is needed
when it is saved.
School Database
Student ID Student   Student     Form   Sex   Age   Class      Class     Room
           Surname   FirstName                      Name       Teacher   Number
S10204     HALL      Taighan     10B    F     13    Maths101   PRJ       651
S10204     HALL      Taighan     10B    M     13    GEO101     RW        532
S10204     HALL      Taighan     10B    F     13    SCI10      CW        161
S10412     CRIST     Graeme      10D    M     14    GEO101     RW        532
S10412     CRIST     Graeme      10D    M     14    HIS101     HJD       541
S10101     CRIST     Graeme      10D    M     14    Maths101   PRJ       651
S10414     HASLETT   Oliver      10D    M     14    Maths101   PRJ       651
S10101     FUNG      JUNE        10A    F     15    Maths101   PRJ       651
S10101     FUNG      JUNE        10B    F     15    GEO101     HJD       532
S10101     FUNF      JUNE        10A    F     15    HIS101     HJD       541




          Table showing data redundancy .
Relational Databases
The simple way to think about this is that
when you create a table of data in a database
you should have fields which directly relate to
the key field of the table.


Student   Student   Student First Form   Sex Age Class Name   Class Teacher   Room
ID        Surname                                                             Number
S10204    HALL      Taighan      10B     F   13   Maths101    PRJ             651

S10204    HALL      Taighan      10B     M   13   GEO101      RW              532

S10204    HALL      Taighan      10B     F   13   SCI10       CW              161
Relational Databases
In our table we can see that the Class teacher,
Class Name and Room Number are not related
to the Student. The Student ID is unique so
the first name, surname, form, Sex is all
related to the student but the other fields do
not.

Student   Student   Student First Form   Sex Age Class Name   Class Teacher   Room
ID        Surname                                                             Number
S10204    HALL      Taighan      10B     F   13   Maths101    PRJ             651

S10204    HALL      Taighan      10B     M   13   GEO101      RW              532

S10204    HALL      Taighan      10B     F   13   SCI10       CW              161
Relational Databases

We can now look at how to remove redundancy
issues a process called normalization.
This can be very complex and we are only going
to look it is a simple way.

Student   Student   Student First Form   Sex Age Class Name   Class Teacher   Room
ID        Surname                                                             Number
S10204    HALL      Taighan      10B     F   13   Maths101    PRJ             651

S10204    HALL      Taighan      10B     M   13   GEO101      RW              532

S10204    HALL      Taighan      10B     F   13   SCI10       CW              161
Removing Redundancy
               (“Normalization”)
Instead of one single table we create 2 tables as
shown below.

   CLASS                   STUDENT
   ClassID                 StudentID
   Class Name              Student First Name
   Class Teacher           Student Surname
   Room Number             Student DOB
                           Student Form
Removing Redundancy
               (“Normalization”)
   CLASS                             STUDENT
   ClassID                           StudentID
   Class Name                        Student First Name
   Class Teacher                     Student Surname
   Room Number                       Student DOB
                                     Student Form

Unfortunately these tables have what is called a many to
many relationship. That is there are many students in
each class and there are many classes for each student.
This kind of relationship will not work for what we need.
Step 2
To solve this problem we create an extra table which contains
the StudentID and ClassID for each student in each class.

What this does is remove the many to much relationship and
replace it with a one to many or many to one relationship.

That is one student can be in many classes and one class has
many students.

We can use the relationships to find the information we need in
each case making use of something called Queries that we will
look at later.
How it looks
STUDENT
                                           CLASS
StudentID
                                           ClassID
FirstName
                                           Class Name
Surname
                                           Class Teacher
DOB
                                           Room Number
Form

                    STUDENTTAKES
                    StudentID
                    ClassID


 This goes a long way to solving our problem but there remains
 a potential problem with the room number field which could
 give use problems in what we want to do with the data. Why ?
STEP 3 (optional?)
  STUDENT
                                              CLASS
  StudentID
                                              ClassID
  FirstName             STUDENTTAKES          Class Name
  Surname               StudentID             Class Teacher
  DOB                   ClassID               Room Number
  Form




Room number is not actually related to the class. What happens if a
class is in more than one room for example? If you were to do the
normalization properly you would need to remove Room Number
and create another table.
Entity Relationship Diagram

This is called an Entity Relationship Diagram and they are
used to show the data structure in a database.


     Student              StudentTakes                Class


                                                   Room Class


                                                     Room
Try it for your self
Lets look at our example we are going to create a database to
store information about videos stored in our library and students
who can borrower from the library. Using the fields listed below
you are going to need to create the table structure for our
Database in Normalized form.

Video     Video   Video           Video     Student      Student     Student Video   Borrow
Title     Year    Description     Genre     First Name   Surname     ID      ID      Data


Titanic   1997    Film about a    Romance   Kate         Winslet     101234 R101     01/12/11
                  sinking ship
Titanic   1997    Film about a    Romance   Leonardo     Di Caprio   120123 R101     06/12/11
                  sinking ship
Star      1977    Film about space Space    Mark         Hamill      130232 s101     05/11/11
Wars
Star      1977    Film about space Space    Harrison     Ford        101222 101      04/12/11
Wars

Mais conteúdo relacionado

Último

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Último (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

Destaque

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destaque (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Basic Relational Databases

  • 2. School Database Student ID Student Student Form Sex Age Class Class Room Surname FirstName Name Teacher Number S10204 HALL Taighan 10B F 13 Maths101 PRJ 651 S10204 HALL Taighan 10B M 13 GEO101 RW 532 S10204 HALL Taighan 10B F 13 SCI10 CW 161 S10412 CRIST Graeme 10D M 14 GEO101 RW 532 S10412 CRIST Graeme 10D M 14 HIS101 HJD 541 S10101  CRIST Graeme 10D M 14 Maths101 PRJ 651 S10414 HASLETT Oliver 10D M 14 Maths101 PRJ 651 S10101 FUNG JUNE 10A F 15 Maths101 PRJ 651 S10101 FUNG JUNE 10B F 15 GEO101 HJD 532 S10101 FUNF  JUNE 10A F 15 HIS101 HJD 541 This is part of a database showing all students and their classes in a school.
  • 3. Data integrity and Data Redundancy These issues can have a significant impact on the ability for a database to actually do the job that it is intended to do. Data Integrity is the idea that information always keeps its meaning. This is particularly difficult when databases get really big. If you imagine the database above includes every student and every class in the school it could contain over 10000 records.
  • 4. School Database Student ID Student Student Form Sex Age Class Class Room Surname FirstName Name Teacher Number S10204 HALL Taighan 10B F 13 Maths101 PRJ 651 S10204 HALL Taighan 10B M 13 GEO101 RW 532 S10204 HALL Taighan 10B F 13 SCI10 CW 161 S10412 CRIST Graeme 10D M 14 GEO101 RW 532 S10412 CRIST Graeme 10D M 14 HIS101 HJD 541 S10101  CRIST Graeme 10D M 14 Maths101 PRJ 651 S10414 HASLETT Oliver 10D M 14 Maths101 PRJ 651 S10101 FUNG JUNE 10A F 15 Maths101 PRJ 651 S10101 FUNG JUNE 10B F 15 GEO101 HJD 532 S10101 FUNF  JUNE 10A F 15 HIS101 HJD 541 This is part of a database showing all students and their classes in a school.
  • 5. Examples of Data integrity Examples of Data integrity  A simple typo means that it might mean that information gets lost if we search for June in the data. This problem is much more likely because of the redundancies issues we will look at later.
  • 6. School Database Student ID Student Student Form Sex Age Class Class Room Surname FirstName Name Teacher Number S10204 HALL Taighan 10B F 13 Maths101 PRJ 651 S10204 HALL Taighan 10B M 13 GEO101 RW 532 S10204 HALL Taighan 10B F 13 SCI10 CW 161 S10412 CRIST Graeme 10D M 14 GEO101 RW 532 S10412 CRIST Graeme 10D M 14 HIS101 HJD 541 S10101  CRIST Graeme 10D M 14 Maths101 PRJ 651 S10414 HASLETT Oliver 10D M 14 Maths101 PRJ 651 S10101 FUNG JUNE 10A F 15 Maths101 PRJ 651 S10101 FUNG JUNE 10B F 15 GEO101 HJD 532 S10101 FUNF  JUNE 10A F 15 HIS101 HJD 541 This is part of a database showing all students and their classes in a school.
  • 7. Examples of Data integrity Examples of Data integrity  This example can cause real problems it shows that the same information in the database can mean two different things is s10101 Graeme or June.
  • 8. School Database Student ID Student Student Form Sex Age Class Class Room Surname FirstName Name Teacher Number S10204 HALL Taighan 10B F 13 Maths101 PRJ 651 S10204 HALL Taighan 10B M 13 GEO101 RW 532 S10204 HALL Taighan 10B F 13 SCI10 CW 161 S10412 CRIST Graeme 10D M 14 GEO101 RW 532 S10412 CRIST Graeme 10D M 14 HIS101 HJD 541 S10101  CRIST Graeme 10D M 14 Maths101 PRJ 651 S10414 HASLETT Oliver 10D M 14 Maths101 PRJ 651 S10101 FUNG JUNE 10A F 15 Maths101 PRJ 651 S10101 FUNG JUNE 10B F 15 GEO101 HJD 532 S10101 FUNF  JUNE 10A F 15 HIS101 HJD 541 This is part of a database showing all students and their classes in a school.
  • 9. Examples of Data integrity Examples of Data integrity  Here we have June in two classes? Which one is right? What if we need to find June in registration urgently
  • 10. Hard to find? They can be really hard to find in this Database there are more integrity errors can you find them?
  • 11. Student ID Student Student Form Sex Age Class Class Room Surname FirstName Name Teacher Number S10204 HALL Taighan 10B F 13 Maths101 PRJ 651 S10204 HALL Taighan 10B M 13 GEO101 RW 532 S10204 HALL Taighan 10B F 13 SCI10 CW 161 S10412 CRIST Graeme 10D M 14 GEO101 RW 532 S10412 CRIST Graeme 10D M 14 HIS101 HJD 541 S10101  CRIST Graeme 10D M 14 Maths101 PRJ 651 S10414 HASLETT Oliver 10D M 14 Maths101 PRJ 651 S10101 FUNG JUNE 10A F 15 Maths101 PRJ 651 S10101 FUNG JUNE 10B F 15 GEO101 HJD 532 S10101 FUNF  JUNE 10A F 15 HIS101 HJD 541
  • 12. Bad or unnecessary Fields Names Age is an example of a bad field name for the obvious reason that it can change at anytime. It would be much better to use DOB as age can always be calculated and ofcourse it does not change. Form may also be unnecessary in this case as the reference number is CODED to give the form. Can you explain the code?
  • 13. Data Redundancy Data redundancy is the where data needs to be entered and stored on more than one occasion. For example if you look at the table you can see that we have entered Oliver Haslett’s first name and surname every time we put him into a class. This can cause problems such as increasing the chance of someone entering his name wrong. It also means more time is needed to enter data and more space is needed when it is saved.
  • 14. School Database Student ID Student Student Form Sex Age Class Class Room Surname FirstName Name Teacher Number S10204 HALL Taighan 10B F 13 Maths101 PRJ 651 S10204 HALL Taighan 10B M 13 GEO101 RW 532 S10204 HALL Taighan 10B F 13 SCI10 CW 161 S10412 CRIST Graeme 10D M 14 GEO101 RW 532 S10412 CRIST Graeme 10D M 14 HIS101 HJD 541 S10101 CRIST Graeme 10D M 14 Maths101 PRJ 651 S10414 HASLETT Oliver 10D M 14 Maths101 PRJ 651 S10101 FUNG JUNE 10A F 15 Maths101 PRJ 651 S10101 FUNG JUNE 10B F 15 GEO101 HJD 532 S10101 FUNF JUNE 10A F 15 HIS101 HJD 541 Table showing data redundancy .
  • 15. Relational Databases The simple way to think about this is that when you create a table of data in a database you should have fields which directly relate to the key field of the table. Student Student Student First Form Sex Age Class Name Class Teacher Room ID Surname Number S10204 HALL Taighan 10B F 13 Maths101 PRJ 651 S10204 HALL Taighan 10B M 13 GEO101 RW 532 S10204 HALL Taighan 10B F 13 SCI10 CW 161
  • 16. Relational Databases In our table we can see that the Class teacher, Class Name and Room Number are not related to the Student. The Student ID is unique so the first name, surname, form, Sex is all related to the student but the other fields do not. Student Student Student First Form Sex Age Class Name Class Teacher Room ID Surname Number S10204 HALL Taighan 10B F 13 Maths101 PRJ 651 S10204 HALL Taighan 10B M 13 GEO101 RW 532 S10204 HALL Taighan 10B F 13 SCI10 CW 161
  • 17. Relational Databases We can now look at how to remove redundancy issues a process called normalization. This can be very complex and we are only going to look it is a simple way. Student Student Student First Form Sex Age Class Name Class Teacher Room ID Surname Number S10204 HALL Taighan 10B F 13 Maths101 PRJ 651 S10204 HALL Taighan 10B M 13 GEO101 RW 532 S10204 HALL Taighan 10B F 13 SCI10 CW 161
  • 18. Removing Redundancy (“Normalization”) Instead of one single table we create 2 tables as shown below. CLASS STUDENT ClassID StudentID Class Name Student First Name Class Teacher Student Surname Room Number Student DOB Student Form
  • 19. Removing Redundancy (“Normalization”) CLASS STUDENT ClassID StudentID Class Name Student First Name Class Teacher Student Surname Room Number Student DOB Student Form Unfortunately these tables have what is called a many to many relationship. That is there are many students in each class and there are many classes for each student. This kind of relationship will not work for what we need.
  • 20. Step 2 To solve this problem we create an extra table which contains the StudentID and ClassID for each student in each class. What this does is remove the many to much relationship and replace it with a one to many or many to one relationship. That is one student can be in many classes and one class has many students. We can use the relationships to find the information we need in each case making use of something called Queries that we will look at later.
  • 21. How it looks STUDENT CLASS StudentID ClassID FirstName Class Name Surname Class Teacher DOB Room Number Form STUDENTTAKES StudentID ClassID This goes a long way to solving our problem but there remains a potential problem with the room number field which could give use problems in what we want to do with the data. Why ?
  • 22. STEP 3 (optional?) STUDENT CLASS StudentID ClassID FirstName STUDENTTAKES Class Name Surname StudentID Class Teacher DOB ClassID Room Number Form Room number is not actually related to the class. What happens if a class is in more than one room for example? If you were to do the normalization properly you would need to remove Room Number and create another table.
  • 23. Entity Relationship Diagram This is called an Entity Relationship Diagram and they are used to show the data structure in a database. Student StudentTakes Class Room Class Room
  • 24. Try it for your self Lets look at our example we are going to create a database to store information about videos stored in our library and students who can borrower from the library. Using the fields listed below you are going to need to create the table structure for our Database in Normalized form. Video Video Video Video Student Student Student Video Borrow Title Year Description Genre First Name Surname ID ID Data Titanic 1997 Film about a Romance Kate Winslet 101234 R101 01/12/11 sinking ship Titanic 1997 Film about a Romance Leonardo Di Caprio 120123 R101 06/12/11 sinking ship Star 1977 Film about space Space Mark Hamill 130232 s101 05/11/11 Wars Star 1977 Film about space Space Harrison Ford 101222 101 04/12/11 Wars