Our world depends on databases Google basically IS a database (index) Facebook is build around databases So is e-Bay & Netflix and X-Box Live Travel agents, schools, doctors and hospitals all rely on them You get the idea!
Databases are so useful because they’re so good at storing info But they do it in a very structured way That’s so the data can also be sorted And so the data can also be searched So overall, what makes databases so special is how they store, sort & search Let’s look at some examples…
Store Search Sort
We’re actually going to look at databases into two stages.
Database Tables Types of Data Relational Databases First, we’ll learn the basics of how databases work: A Database Tables B Types of Data C Relational Databases
A Database Tables So we’ve said what makes databases so special is how they store, sort & search But how can they do that? The secret is that they work in a very structured or organised way This starts with the way that all data is stored in what are called tables…
Database Tables A Here’s a database table for members of a club... Field name Record Field
Database Tables A Here’s a database table for members of a club... Field name Record Field
Database Tables A Here’s a database table for members of a club... Field name Record Primary Key Field
Database Tables Recap A Databases store info in a structured way Data in a database is stored in a table Each row is called a record Each column is called a field A special field called the primary key holds a unique identifier for each record
‘Unique identifiers’ are everywhere!
Database Tables Recap A Table Field name Recordl Primary Key Field All this data is stored in a ?? Table This is a ?? Field name This is a ?? Recordl This is the ?? This is a ?? Primary Key Field
Database Tables Recap A This table has ____ records 4 There are ____ fields 4 The primary key is called _______ LessonID
A Database Tables B Types of Data C Relational Databases
B Types of Data A second secret to how databases work is the way they handle different types of data Let’s look at an example…
Types of Data B Can you spot the different types of data? We call these ‘data types’ Text Numbers Dates
B Types of Data Database tables can store different data types, such as... Text Numbers Dates When building a database, you say what type of data can go in each field This can help prevent errors, such as checking that dates are DD/MM/YY
A Database Tables B Types of Data C Relational Databases
Relational Databases C Simple databases with just one data table are called flat file databases. But using only one table creates BIG problems for larger systems because lots of data can be duplicated and the database becomes very inefficient. So advanced databases use multiple tables They are called relational databases Let’s look at why they are needed…
Relational Databases C Notice that several patients see Dr Brown So her details are duplicated. This is called redundant data because copies are inefficient & cause inconsistencies Can you spot one?
Relational Databases C PatientID DocID Primary Key Foreign Key DocID
Relational Databases We show this relationship in a diagram C Relational Databases We show this relationship in a diagram Doctors DocID Surname Department Mobile Patients Patient ID Forename Surname DocID It’s a ‘One To Many’ relationship One doctor can treat many patients
Relational Databases C Car Club Again, data is duplicated or redundant Redundant data causes inconsistencies Can you spot one?
Relational Databases C Car Club SupplierID SupplierID 1 2 3 1 1 2 1 2
Relational Databases We show this relationship in a diagram C Relational Databases We show this relationship in a diagram Supplier SupplierID CarSupplier Address1 Town Postcode Member MemberID Forename Surname Car Reg Car Supplier It’s a ‘One To Many’ relationship One Car Supplier can supply many members
Relational Databases C Dog Kennel Business Again, data is duplicated or redundant Redundant data causes inconsistencies Can you spot any?
Relational Databases C Dog Kennel Business VetID VetID 3 1 2 2 3 2 1 Betta Vetz 2 Top Vets 3 West Vets
Relational Databases We show this relationship in a diagram C Relational Databases We show this relationship in a diagram Vet VetID VetName Address1 Town Postcode Pets PetID Name Owner Name Owner Mobile Vet ID It’s a ‘One To Many’ relationship One Car Supplier can supply many members