Presentation is loading. Please wait.

Presentation is loading. Please wait.

Databases Explained Tables © Dolinski 2007.

Similar presentations


Presentation on theme: "Databases Explained Tables © Dolinski 2007."— Presentation transcript:

1 Databases Explained Tables © Dolinski 2007

2 What you will learn What a database is What a table is
How tables are structured Difference between a flat file database and a relational database

3 What is a database? A database is like a filing cabinet.
You can store records about different things inside a filing cabinet, just like in a database! They are used by all organisations to keep records about stock, personnel, projects and lots more.

4 Why use databases? Databases make storing information a lot easier.
Files are stored in an organised way. Files can be searched quickly. You can merge database software with other software: Mail merging is a way of extracting information from a database to speed up a process such as writing a letter to lots of people.

5 What is a database made of?
Primarily – A database is made up of tables. A table looks a lot like a spreadsheet. The only difference is YOU decide how many rows and columns there are.

6 What is a table? A table will hold lots of records.
The table is like a draw inside a filing cabinet. Each draw holds a different kind of record.

7 What is a table? For example, a table may hold information about all the members of a video rental shop.

8 Where can you find a database?
Your mobile phones have a database built into them… Your address book has a single table which stores information about people’s telephone numbers!

9 How do tables work? Every table is made up of rows and columns.
A column represents a piece of data. A row is a collection of data. This collection makes up information. This collection of information is known as a record.

10 Data Types Each piece of data must have a Data Type. These include:
Auto number Text Number Date/Time Yes/No

11 Member table data types
This table contains the following data types: MemberID – Auto Number FirstName – Text LastName – Text DOB – Date/Time HouseNo – Text PostCode – Text Mobile - Text

12 Why are some numbers text?
Think about Excel. What would happen if you type in the number 021? How would it be displayed? Number data types should be used if you are going to be performing a calculation with the data.

13 Questions What are the data types for the following things?
A unique number A name A birthday A telephone number A postcode Someone’s Height in cm A field which indicates if someone has paid for their order.

14 How are tables linked? Tables are linked using relationships.
Relationships work by having a common piece of data in both tables.

15 A dog is a man’s best friend!
A man can own many dogs. A dog can be a friend to only one man.

16 How are tables involved?
A table is used to store records about a particular thing. In this case we need two tables: OWNER DOG Each table needs to have its own data.

17 OWNER table DOG table OwnerID Name DogID 01 Bill D01 D02 02 Nancy D03
Breed D01 Turnip Bulldog D02 Spot Poodle D03 Pooch

18 OWNER table DOG table OwnerID Name DogID 01 Bill D01 D02 02 Nancy D03
We can cross reference to see who owns which dog! DogID Name Breed D01 Turnip Bulldog D02 Spot Poodle D03 Pooch

19 OWNER table DOG table OwnerID Name DogID 01 Bill D01 D02 02 Nancy D03
We can cross reference to see who owns which dog! DogID Name Breed D01 Turnip Bulldog D02 Spot Poodle D03 Pooch

20 OWNER table DOG table OwnerID Name DogID 01 Bill D01 D02 02 Nancy D03
Repeated attributes aren’t very good. If Bill’s name changed then we would have to change ALL the records for bill. How can we fix this? DOG table DogID Name Breed D01 Turnip Bulldog D02 Spot Poodle D03 Pooch

21 The solution. Add a third table Owner Owns Dog
Now if we change a name it wont affect any other table. OwnerID Name 01 Bill 02 Nancy OwnerID DogID 01 D01 D02 02 D03 DogID Name Breed D01 Turnip Bulldog D02 Spot Poodle D03 Pooch

22 Students and their classes
A student has many lessons. A lesson has many students. This is a many-to-many relationship. A problem with many-to-many relationship is that data can be duplicated many times within one table… Something we already know we need to avoid.

23 Many-to-Many problem Student Lesson We have lots of repeated data…boo!
StudentID Name ClassID 01 Wilkinson ICT Maths German 02 Masters Art French LessonID Teacher StudentID ICT Dolinski 01 02 Maths Wade Art Cooper German White French Conner

24 Fixing the many-to-many
Add a third table! Student Stu_Les Lesson StudentID Name 01 Wilkinson 02 Masters StudentID LessonID 01 ICT Maths German 02 Art French LessonID Teacher ICT Dolinski Maths Wade Art Cooper German White French Conner

25 Things to remember A table must have a primary key.
A primary key must be unique…only one record can have it. The primary key is used to link to a foreign key in another table. The foreign key is the primary key the linking table.

26 Student Lesson Example
The primary key for students is their ID. The foreign key is in the Stu_Les table. Student Stu_Les Lesson StudentID Name 01 Wilkinson 02 Masters StudentID LessonID 01 ICT Maths German 02 Art French LessonID Teacher ICT Dolinski Maths Wade Art Cooper German White French Conner

27 Student Lesson Example
The primary key for students is the ID. The foreign key is in the Stu_Les table. Student Stu_Les Lesson StudentID Name 01 Wilkinson 02 Masters StudentID LessonID 01 ICT Maths German 02 Art French LessonID Teacher ICT Dolinski Maths Wade Art Cooper German White French Conner

28 Student Lesson Example
The combination of these two keys makes a unique primary key (or compound key). Student Stu_Les Lesson StudentID Name 01 Wilkinson 02 Masters StudentID LessonID 01 ICT Maths German 02 Art French LessonID Teacher ICT Dolinski Maths Wade Art Cooper German White French Conner

29 Student Lesson Example
Although we have some repeating data, it is minimised. What is the other benefit of having our tables like this? Student Stu_Les Lesson StudentID Name 01 Wilkinson 02 Masters StudentID LessonID 01 ICT Maths German 02 Art French LessonID Teacher ICT Dolinski Maths Wade Art Cooper German White French Conner


Download ppt "Databases Explained Tables © Dolinski 2007."

Similar presentations


Ads by Google