Download presentation
Presentation is loading. Please wait.
Published byRalph Jefferson Modified over 9 years ago
1
1 What is database? Why do we use databases?
2
2 This is a little database. One department has some staffs (teachers)
3
3 This is a larger database.
4
4 Before you can store information using a computer, you need to think about exactly which pieces of information you are going store, and what type of information they are. The first thing you need to think about are the fields you are going to use. Fields are the categories of information that your database is going to store.
5
5 Example: O ur school gives out merits (awards) to students who have worked well. O ur school gives out merits (awards) to students who have worked well. To produce a merits database, you would include fields such as : To produce a merits database, you would include fields such as : – Student Name –Group – Subject – Date – Reason for Merit – Teacher, etc. – Teacher, etc.
6
6 Once you've decided on the fields you're going to use, you can start entering the data. All the information for one person or thing, i.e. the information for all fields gathered together, is called a record. In the merits database (table) example, therefore, each student who had a merit would have a record in the database. All the records are then gathered together in a table. Once you've decided on the fields you're going to use, you can start entering the data. All the information for one person or thing, i.e. the information for all fields gathered together, is called a record. In the merits database (table) example, therefore, each student who had a merit would have a record in the database. All the records are then gathered together in a table.
7
7 Field Types Most database programs allow, or rather require, that you give each field in your database a type. The field type indicates what type of information is going to be stored in that field. Most database programs allow, or rather require, that you give each field in your database a type. The field type indicates what type of information is going to be stored in that field. Common field types are: Common field types are: –whole numbers (1,2,3...) –decimal numbers (1.23,one point two three) –text –Dates (2nd March 2003) –Boolean (or yes/no)
8
8
9
9 Notes: Some more advanced databases also let you store multimedia objects, such as pictures or sounds Some more advanced databases also let you store multimedia objects, such as pictures or sounds Field types form a basic type of validation in that the database won't allow you to enter, say, text in a date field.(1) Field types form a basic type of validation in that the database won't allow you to enter, say, text in a date field.(1) They also facilitate sorting, as the database "knows" more about the contents of the field. (2) They also facilitate sorting, as the database "knows" more about the contents of the field. (2)
10
10 Key Field/Unique Key In order to produce a logical structure for your database, there should be something unique about each record in your database. This will normally be the contents of one particular field, called the key field.(1) In order to produce a logical structure for your database, there should be something unique about each record in your database. This will normally be the contents of one particular field, called the key field.(1) Sometimes you can't identify a single key field in your database table. (2) Sometimes you can't identify a single key field in your database table. (2) In cases such as this, you can create what is known as a compound key - a combination of fields that is unique. This can be any number of fields, but should be the minimum number required to produced a unique description of the record. (3) In cases such as this, you can create what is known as a compound key - a combination of fields that is unique. This can be any number of fields, but should be the minimum number required to produced a unique description of the record. (3)
11
11 Cars - registration number Cars - registration number Table(Name, Mother’s name, Address, Company name) Table(Name, Mother’s name, Address, Company name) Compound key e.g: (first name,city,street,mother’s first name) Compound key e.g: (first name,city,street,mother’s first name) Compound key in merit: ( student, date and subject ) Compound key in merit: ( student, date and subject )
12
12 Indexes The final thing you can create for your fields is an index. Once you've started using your database, the data can be stored in the table in any order, probably the order in which you entered it. (1) The final thing you can create for your fields is an index. Once you've started using your database, the data can be stored in the table in any order, probably the order in which you entered it. (1) An index is just like the index in a book - it is an extra bit added on to the database to help the database program find records quickly. (2) An index is just like the index in a book - it is an extra bit added on to the database to help the database program find records quickly. (2)
13
13 1White 2Black 3Yellow 4Brown 5Red 6Green 7Gray 8Orange 9Pink 10Violet2Black4Brown 7Gray 6Green 8Orange 9Pink 5Red 10Violet 3Yellow 1White The key is the name of colours. Index table
14
14 Validation Validation is the name given to the process whereby the information entered in the database is checked to ensure that it makes sense (understandable). (1) Validation is the name given to the process whereby the information entered in the database is checked to ensure that it makes sense (understandable). (1)
15
15 Basic types of validation Type: Type: Presence: Presence: Uniqueness Uniqueness Range Range Format Format Multiple Choice Multiple Choice Referential Integrity Referential Integrity
16
16 Type The use of field types forms a basic type of validation. If you make a particular field numeric (i.e. a number), for example, then it won't let you enter any letters or other non- numeric characters. (1) The use of field types forms a basic type of validation. If you make a particular field numeric (i.e. a number), for example, then it won't let you enter any letters or other non- numeric characters. (1)
17
17 Presence This type of validation might go by different names, depending on your database program - sometimes it's called something like Allow Blank or mandatory (kötelező) for example. This type of validation forces the user to enter the data in that field. (1) This type of validation might go by different names, depending on your database program - sometimes it's called something like Allow Blank or mandatory (kötelező) for example. This type of validation forces the user to enter the data in that field. (1)
18
18 Uniqueness Some database programs allow you to check whether the contents of a particular field are unique. This might be useful to prevent users entering the same information twice. For example, if you were creating a car database, you should make the registration number field unique as no two cars should have the same number. Some database programs allow you to check whether the contents of a particular field are unique. This might be useful to prevent users entering the same information twice. For example, if you were creating a car database, you should make the registration number field unique as no two cars should have the same number.
19
19 Range If you're using a number field, then you might want to limit the range of inputs. For example, you might want to limit prices in a stock database so that they are all positive, or limit the range of a percentage field so that the values entered are between 0 and 100. If you're using a number field, then you might want to limit the range of inputs. For example, you might want to limit prices in a stock database so that they are all positive, or limit the range of a percentage field so that the values entered are between 0 and 100.
20
20 Format You might have a field in your database that requires an entry in a particular format. You might have a field in your database that requires an entry in a particular format. A simple example might be a date, or piece of text of a certain length. A simple example might be a date, or piece of text of a certain length. More complex examples might include things like postcodes, or National Insurance or driving licence numbers. More complex examples might include things like postcodes, or National Insurance or driving licence numbers. If you're using database management system (such as Access), you can define your own formats using an input mask, which defines the valid characters. If you're using database management system (such as Access), you can define your own formats using an input mask, which defines the valid characters.
21
21 Multiple Choice A good way to validate fields is to use multiple choice responses. These might take the form of a list box, combo box, or radio button. For example, you could create a field that would only allow the user to select from Yes or No, or Male or Female. This can be an especially useful techniques in database applications such as Access, which allow you to dynamically generate the choices. A good way to validate fields is to use multiple choice responses. These might take the form of a list box, combo box, or radio button. For example, you could create a field that would only allow the user to select from Yes or No, or Male or Female. This can be an especially useful techniques in database applications such as Access, which allow you to dynamically generate the choices.
22
22 Choose an item from these scrolldown tables, radio box or spinner: Choose an item from these scrolldown tables, radio box or spinner:
23
23 Referential Integrity Finally, if you're using a relational database, then you can enforce referential integrity to validate inputs. This means you can check entries in certain fields against values in other tables. For example, in the merits database, when a new merit is entered, you could check the names of the students and teachers against the student and staff tables, to prevent either spelling mistakes, or the entry of merits for students that don't exist. Finally, if you're using a relational database, then you can enforce referential integrity to validate inputs. This means you can check entries in certain fields against values in other tables. For example, in the merits database, when a new merit is entered, you could check the names of the students and teachers against the student and staff tables, to prevent either spelling mistakes, or the entry of merits for students that don't exist.
24
24 So far we've only discussed having one table in a database. In the merits database, for example, we've talked about using the following fields to store the information about the merits:
25
25 Data Redundancy This database structure would do the job, but think about what would happen as you enter the merits. For each new merit you add, you need to enter all of the teacher and student details each time. This would involve a lot of data being duplicated, and therefore take up a lot more disc space. This is known as redundancy. This database structure would do the job, but think about what would happen as you enter the merits. For each new merit you add, you need to enter all of the teacher and student details each time. This would involve a lot of data being duplicated, and therefore take up a lot more disc space. This is known as redundancy.
26
26 Now let’s go back to our data We have to separate out the name of the students, the teachers and the groups into new tables. In these new tables we have to create ID (Identification) numbers to the teachers, the students and the groups. In the main table (the merits) we no need the columns Name, Group, Year and Tutor, instead of these we need only three simple column with the ID_teacher, ID_student and the ID_groups.. The tables are then linked by the ID_teacher,ID_student and the ID_groups.
27
27 1 1 1
28
28
29
29 The tables, - the logical units, or entities, - in the merits system are the students, the teahers the groups, and the merits themselves. This means that the details of the students the teachers and the groups only need to be entered once. When you enter a new merit, you only need to enter enough information to identify the students, the teachers and the groups - the remaining information can then be looked up from the teacher, group and student tables. The tables, - the logical units, or entities, - in the merits system are the students, the teahers the groups, and the merits themselves. This means that the details of the students the teachers and the groups only need to be entered once. When you enter a new merit, you only need to enter enough information to identify the students, the teachers and the groups - the remaining information can then be looked up from the teacher, group and student tables.
30
30 Degree of Relationship You will probably have noticed that the relationships have little symbols at the end, either a 1 or the infinity symbol. These indicate the degree of the relationship, where the infinity symbol means many. The degree indicates the nature of the relationship between the entities - for example, in the merits database shown above, one teacher can give many merits, and each student can have many merits give n to them. On the other hand, each merit can only be given by one teacher, and can only be given to one student.
31
31 Obviously, there are three possible types of relationship: Obviously, there are three possible types of relationship: –one-to-one –one-to-many (or vice-versa) –many-to-many To examine the types of relationship we need a new example:
32
32 In this example, the jokes would be stored entirely in the database. In this example, the jokes would be stored entirely in the database. For our joke database, we would probably start with a table called "jokes" which would contain a list of jokes. Our "jokes" table might have columns for the text of the jokes, the author, the e-mail of the author and the dates of the jokes were added to the database. For our joke database, we would probably start with a table called "jokes" which would contain a list of jokes. Our "jokes" table might have columns for the text of the jokes, the author, the e-mail of the author and the dates of the jokes were added to the database.
33
33 1 Kevin Yang " Why did the chicken cross the road?” To get to the other side! js@mail. joke 2 Kevin Yang What do you get if you cross a kangeroo with a sheep? A wooly jumper! ky@mail.joke 3 Joan Smith What do you call a waitress balancing 6 beers on her head ? Beatrix! ky@mail.joke Table of jokes But, I hope that to this time everybody know that there is something problem with this single table. What if an author changed her email address? She might begin submitting new jokes using the new address, but all the old jokes would still have the old address attached to them. Looking at your database, you might just think there were two different people with the same name Smith submitting to your database.
34
34 What the above two tables show are three jokes and two authors. The AID column (short for "Author ID") of the Jokes table provides a relationship between the two tables (indicating that Kevin Yank submitted jokes 1 and 2 and Joan Smith submitted joke 3). Notice also that, since each author now only appears once in the database, and appears independently of the jokes he or she has submitted, we have avoided all the problems outlined above 11 21 32 AID1 Kevin Yang 2 Yoan Smith AID
35
35 one-to-one relationship In the case of a simple one-to-one relationship, a single table is all that is needed. An example of a one-to-one relationship that we have seen is the email address of each author in our joke database. Since there will be one e-mail address for each author, and one author for each e-mail address, there is no reason to split the addresses off into a separate table. In the case of a simple one-to-one relationship, a single table is all that is needed. An example of a one-to-one relationship that we have seen is the email address of each author in our joke database. Since there will be one e-mail address for each author, and one author for each e-mail address, there is no reason to split the addresses off into a separate table.
36
36 many-to-one relationship A many-to-one relationship is a little more complicated, but we have seen one of these already as well. Each joke in our database is associated with just one author, but many jokes may have been written by that one author. This joke-author relationship is many-to-one. A many-to-one relationship is a little more complicated, but we have seen one of these already as well. Each joke in our database is associated with just one author, but many jokes may have been written by that one author. This joke-author relationship is many-to-one.
37
37 one-to-many relationship In our database so far, we have assumed that each author only has one email address.(1) In our database so far, we have assumed that each author only has one email address.(1) If we did, however, want to support multiple email addresses, we would be faced with a one-to-many relationship (one author may have many email addresses, but each email address belongs to exactly one author). If we did, however, want to support multiple email addresses, we would be faced with a one-to-many relationship (one author may have many email addresses, but each email address belongs to exactly one author).
38
38 Many-to-Many Relationships You decide to place your jokes into categories such as "Knock-Knock Jokes", "Crossing the Road Jokes", "Lawyer Jokes", and "Political Jokes". Remembering our rule of thumb from earlier, you identify joke categories as a different type of "thing", and create a new table for them: You decide to place your jokes into categories such as "Knock-Knock Jokes", "Crossing the Road Jokes", "Lawyer Jokes", and "Political Jokes". Remembering our rule of thumb from earlier, you identify joke categories as a different type of "thing", and create a new table for them:
39
39 1 Crossing road 2Lawyers Now comes the very difficult task of giving categories to your jokes. It occurs to you that a "political" joke might also be a "crossing the road" joke, and a "knock-knock" joke might also be a "lawyer" joke. A single joke might belong to many categories, and each category will contain many jokes. This is a many-to-many relationship.
40
40 The correct way to represent a many-to-many relationship is to use a "lookup table". This is a table that contains no actual data, but which serves to define pairs of entries that are related. Here's what the database design would look like for our joke categories: JIDCID 11 12 22 The JokeLookup table associates joke ID's ( JID ) with category ID's ( CID ). Looking at the above example, we can see that the joke beginning with " Why did the chicken …" belongs to both the „Crossing road" and "Lawyer" categories.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.