Presentation on theme: "Version 21 Information Systems Design and Development Databases A database is a collection of data or information which is held together in an organised."— Presentation transcript:
Version 21 Information Systems Design and Development Databases A database is a collection of data or information which is held together in an organised or logical way. Link 1 – What is an information System? Today databases exist almost entirely on computer systems. A database is made up of a file, records and fields.
Version 22 File Data is stored in files. A file is a collection of data on one topic in a simple database. Files are made up of sets of records. Record A record is all the information about one person or thing in the file, for example one book in a book database. Records can be updated, deleted or new records can be inserted. Field Each bit of information in a record is stored in a field. Each field has a field name eg title in a book database. Fields can be deleted or added. Link 2 – What is a Database?
Version 23 Field Types Number – stores numbers, e.g. exam marks Text – stores words or numbers not being used for calculations, e.g. surname, phone no. Graphic - stores images, e.g. photographs Date - stores dates, e.g. date of birth Time – stores a time of day, e.g. the start time of an exam Calculated – stores a formula and uses 1 or more of the other fields to carry out a calculation. The answer is displayed. e.g. averages or totals Object (OLE) field. In Microsoft Access, for example, an object field can hold a word document, an Excel spreadsheet or a Paint graphic.
Version 24 More Field Types Boolean – stores just two values, eg. ‘Yes’ or ‘’No’. Eg. Married? Link - stores a hyperlink within the database or a hyperlink to a document outside the database. e.g. To another record or to an Internet site.
Version 25 Validation Validation is the process of checking that data entered into a system makes sense and is allowable. Types of validation check: Presence check Restricted choice Field length check Field range check
Version 26 Presence Check Checks that data has been entered and that the data field has not been left blank. Restricted Choice Forces the user to enter data from a list of acceptable values e.g. from a dropdown menu with the days of the week. Field Length CheckChecks that the data entered is of a certain length e.g. year with 4 digits. Field Range CheckChecks that the data entered is within a certain range of numbers e.g. month entered should be from 1 to 12.
Version 27 Sorting Putting the records into some kind of order. Records can be sorted into ascending or descending order. More than one sort can be carried out. e.g. First NameSurname AbbyBrown CarolBrown AlisonCampbell JohnGreen RobertMcDonald SallyMcDonald Searching Using one or more fields to search for records from the database. A primary sort has been done on the ‘Surname’ field then a second sort on the ‘First Name’ field.
Version 28 Flat File Database A simple database structure has one table containing all the fields and the data they contain. Relational Database A database which contains more than one table. The tables are linked together via a relationship between the primary key of one table and the foreign key of another table. Relational databases reduce data duplication and data inconsistency. Key Field – a field in a record that is used to uniquely identify a record in the database eg. reference number, account number. Link 3 – More About Databases
Version 29 A primary key field and a foreign key field are used to make relationships between tables. A primary key uniquely identifies each record in a database. For example, a primary key could be an ID number or an account number. A Table can only have 1 primary key. Link 4 – Even More about Databases A foreign key enables you to set up relationships, or links, between tables in a database.
Look at the following flat file database. The data stored shows flights leaving Glasgow airport and the pilot who will captain the flight. Look for data duplication and data inconsistency 10Version 2
Example 1 Flights Database Flight IDDateDestinationPilot IDSurnameForenameSalary (£) EZ258012/03/14LondonPID0001CaseyNicola50,000 EZ321014/13/14ParisPID0002SmithJames46,500 EZ255014/03/14DublinPID0001CaseyNicolas50,000 BA123112/03/14RomePID1001MillerJohn50,000 BA122914/03/14MadridPID1001MillerJohn50,000 AA098114/03/14New YorkPID2001MurrayAnne65,000 AA098517/03/14LAPID2001MurrayAnne65,000 Version 211 Data duplication Data inconsistency
Example 1 Flights Database 1. How the data in the table will be split. It could be library members and the books they borrow. It could be teachers and the pupils they teach. 2. What are the primary and foreign keys? Decide on the primary key for each table. (the primary key must be unique for each record). Decide which field will link the tables. This will be the primary key in one table and becomes the foreign key in the other table. In order to split a table into two tables you need to decide: 12Version 2
Flight IDDateDestinationPilot IDSurnameForenameSalary (£) EZ258012/03/14LondonPID0001CaseyNicola50,000 EZ321014/13/14ParisPID0002SmithJames46,500 EZ255014/03/14DublinPID0001CaseyNicolas50,000 BA123112/03/14RomePID1001MillerJohn50,000 BA122914/03/14MadridPID1001MillerJohn50,000 AA098114/03/14New YorkPID2001MurrayAnne65,000 AA098517/03/14LAPID2001MurrayAnne65,000 Flight Table Pilot Table Duplications can be removed Link 13Version 2
Example 1 Flights Database We can now split this flat file into two tables, one table to store the flight details and the other to store the pilot details. Flight ID DateDestina tion Pilot ID EZ258012/03/14LondonPID0001 EZ321014/13/14ParisPID0002 EZ255014/03/14DublinPID0001 BA123112/03/14RomePID1001 BA122914/03/14MadridPID1001 AA098114/03/14New York PID2001 AA098517/03/14LAPID2001 Pilot IDSurnameForenameSalary (£) PID0001CaseyNicola50,000 PID0002SmithJames46,500 PID1001MillerJohn50,000 PID2001MurrayAnne65,000 Version 214 We then link the two tables on the PilotID field. Primary Key Foreign Key PilotID is known as the foreign key in the Flight table. Flight Table Pilot Table
Example 2 Library Database Version 215 Member IDMember Name TelephoneBook Reference Book titleDate Borrowed KP102Mary Smith BK345The Green Mile 17/01/14 KP982James Main BK287The Dark Tower 15/01/14 KP102Mary Smith BK290Pride and Prejudice 17/01/14 KP982Jimmy Main BK205Emma15/01/14 KP982James Main BK106A Fine Balance 20/01/14 KP345Jo Jones BK239Sunset Song 21/01/14 Data duplication Data inconsistency
Version 216 Member IDMember Name TelephoneBook Reference Book titleDate Borrowed KP102Mary Smith BK345The Green Mile 17/01/14 KP982James Main BK287The Dark Tower 15/01/14 KP102Mary Smith BK290Pride and Prejudice 17/01/14 KP982Jimmy Main BK205Emma15/01/14 KP982James Main BK106A Fine Balance 20/01/14 KP345Jo Jones BK239Sunset Song 21/01/14 Member Table Book Table Link
Example 2 Library Database We can now split this flat file into two tables. Version 217 We then link the two tables on the MemberID field. Primary Key Foreign Key MemberID is known as the foreign key in the Book table. Member ID Book Reference Book title Date Borrowed KP102BK345The Green Mile 17/01/14 KP982BK287The Dark Tower 15/01/14 KP102BK290Pride and Prejudice 17/01/14 KP982BK205Emma15/01/14 KP982BK106A Fine Balance 20/01/14 KP345BK239Sunset Song 21/01/14 Member Name Telephone Member ID Mary Smith KP102 James Main KP345 Jo Jones KP982 Book Table Member Table
Example 3 Police Database SurnameForenameNicknameSexHeigh t (M) CrimeTypeDate Arrested Police Ref ID MathersMichaelEminemMale1.68Burglary12/03/13GCR001 SmithKevinSmithyMale1.54Kidnap03/06/12GCR320 MitchellGaryGazzaMale1.80Forgery08/11/12GCR458 SmithKevinSmithyMale1.54Assault13/07/13GCR239 MathersMichaelEminemMale1.68Bank Robbery13/06/13GCR289 MitchellGaryGazzaMale1.54Hacking09/06/13GCR310 JonesAnneJoJoFemale1.32Dangerous driving 13/06/13GCR201 Link? 18Version 2
Example 3 Police Database However in the criminal table there is no obvious primary key. When this happens another field should be added that will become the primary key. This can simply be an autonumber field. In this example we want to split the database into two tables, one containing the data about a criminal and the other containing the data about the crime. 19Version 2
IDSurnameForenameNicknameSexHeight (M)Crime Type Date Arrested Police Ref ID 1MathersMichaelEminemMale1.68Burglary12/03/13GCR001 2SmithKevinSmithyMale1.54Kidnap03/06/12GCR320 3MitchellGaryGazzaMale1.80Forgery08/11/12GCR458 2SmithKevinSmithyMale1.54Assault13/07/13GCR239 1MathersMichaelEminemMale1.68Bank Robbery 13/06/13GCR289 3MitchellGaryGazzaMale1.54Hacking09/06/13GCR310 4JonesAnneJoJoFemale1.32Dangerous driving 13/06/13GCR201 Criminal TableCrime Table Link 20Version 2
Example 3 Police Database We have split this flat file into two tables. Version 221 Criminal ID SurnameForenameNicknameSexHeight (M) 1MathersMichaelEminemMale1.68 2SmithKevinSmithyMale1.54 3MitchellGaryGazzaMale1.80 4JonesAnneJoJoFemale1.32 Primary Key Criminal Table
Example 3 Police Database. Version 222 The two tables are linked by the Criminal ID field. Primary Key Foreign Key Crime TypeDate ArrestedPolice Ref IDCriminal ID Burglary12/03/13GCR0011 Kidnap03/06/12GCR3202 Forgery08/11/12GCR4583 Assault13/07/13GCR2392 Bank Robbery13/06/13GCR2891 Hacking09/06/13GCR3103 Dangerous driving13/06/13GCR2014 Crime Table
Example 4 Music Instructors The next example is a database containing a list of music instructors and the students they teach. The table contains data duplication and needs to broken into 2 tables that are linked by one field. Consider what the two tables should be what the primary key for each table should be what the foreign key should be 23Version 2
Example 4 Music Instructors InstructorInstrumentCost per lesson Student Forename Student surname Age Mrs Mrs Mr Mr Ms Ms Ms 24Version 2
Example 4 Music Instructors Version 225 Primary Key Instructor ID TeacherInstrumentCost per lesson 1Mrs KeysPiano£ Mr BellClarinet£ Ms WattViolin£18.00 Instructor Table Autonumber field added
Example 4 Music Instructors Version 226 We then link the two tables on the Instructor ID field. Primary KeyForeign Key The two tables are linked by the Instructor ID field. Student Forename Student Surname Age Instructor ID Student Table
Music Instructors in Access Link to Access file Let’s now look at the implementation of this data in MS Access. 27Version 2