Presentation is loading. Please wait.

Presentation is loading. Please wait.

N5 Databases Notes Information Systems Design & Development: Structures and links.

Similar presentations


Presentation on theme: "N5 Databases Notes Information Systems Design & Development: Structures and links."— Presentation transcript:

1 N5 Databases Notes Information Systems Design & Development: Structures and links

2 Contents Flat File vs Linked Tables & Keys ◦ Questions Questions Splitting Database Tables ◦ Questions Questions Data Types & Validation ◦ Questions Questions Database Operations ◦ Questions Questions

3 Flat File Databases Flat file databases contain a single table of data Each single item of information is a field. In this flat file database, the columns are all the different values stored for that field The collection of all the different fields about one item, person or object is a record In this flat file database, the rows are all individual records The collection of all information in the database table is known as the file

4 Flat File Databases There are disadvantages to using flat file databases: Flat file databases can have data duplication – the same items of data can reappear across multiple rows Data duplication is inefficient in terms of data storage. It can also result in modification errors – where a change is made to some but not all of the duplicated data

5 Linked Tables Flat file databases should be split into linked tables to prevent the problems caused by data duplication Because information is stored in different tables, there is no longer any data duplication. This also removes the risk of modification errors

6 Linked Tables Key fields are used to link tables together In the example below, the Movie ID and Star ID fields appear in different tables. This allows different tables to be linked together. The information in the different tables can then be joined together

7 Key Field The primary key field in a table is a unique identifier for records in that table. Every table must have a primary key. The primary key can contain no duplicate values A foreign key is a field in a table that uniquely identifies a record in a different table Not every table requires a foreign key. The foreign key field in a table is usually the primary key field in the related table

8 Questions – Flat Files vs Linked Tables & Keys Answer questions in full sentences! 1. Describe the difference between flat file database structures and linked tables database structures 2. What is data duplication? Explain how it is inefficient 3. What is a modification error? 4. How do linked tables prevent data duplication? 5. What is a primary key? 6. Explain why the value in a primary key field has to be unique 7. What is a foreign key? 8. Why is the foreign key field in a table often the primary key of a different table?

9 Splitting Tables Take the following steps to split up tables with data duplication ◦ Identify columns with duplicated data ◦ Split into two tables, one for duplicated columns, one for others ◦ Identify primary keys ◦ Add primary key from table with duplicated columns to other table as foreign key Dept Dept ID Dept Name Manager Product Product Code Product Type Product Name Dept ID * 1 8

10 Identify Columns With Duplicated Data The Dept ID, Dept Name and Department Manager columns all show duplicated values Make sure that the same duplicates always occur in the same rows – Where Dept ID 4 is duplicated, it is always duplicated with the Toiletries Dept Name and H Green as the Department Manager

11 Split Into Tables You will need to split the flat file table into two. One table should be contain the fields with duplicated values All other fields should be added to the other table Give the two new tables a meaningful name based on their contents Dept Dept ID Dept Name Manager Product Product Code Product Type Product Name

12 Identify Primary Keys You will need to identify a suitable primary key for both tables The primary key field should not contain duplicate values. Fields that are an ID number are usually used as primary key fields Mark the primary key field by underlining it or writing the letters PK next to it Remember, although we split the table based on duplicate values, the duplicate rows will be removed. This will allow us to select a primary key field for the table that contained duplicated values Dept Dept ID Dept Name Manager Product Product Code Product Type Product Name

13 Add a Foreign Key The final step is to link the tables by adding a foreign key The primary key from the table that contained the duplicated values should be added to the other table Mark it with a * or the letters FK to indicate it is the foreign key Dept Dept ID Dept Name Manager Product Product Code Product Type Product Name Dept ID * 1 8

14 Questions – Splitting Tables Split the following flat file tables into two linked tables. Identify primary and foreign keys 1. 2.

15 Fields & Data Types A field is a single element of information about one thing When designing a database, fields have a number of properties to describe how the information will be stored. The data type of a field describes what sort of information it will store. This affects how the information is encoded in binary on the computer Database data types include:  Text  Numbers  Date & time  Calculated fields  Graphics  Hyperlinks  Boolean Different database will describe these type differently

16 Data Types Text: Text fields store letters, numeric characters and symbols. ASCII or Unicode is used for storing text Numbers: Number fields store numeric values using binary Date & Time: Date and time fields are a special kind of number field. Multiple numbers are stored in binary to represent the component parts of a date and / or time such as year, month, day, hours, minutes and seconds Calculated: A calculated field’s value is not stored. Instead it is worked out using a formula and values in other fields. This saves storage space and can prevent update errors. Age is a good example of a calculated field as using a calculated field will automatically update age every birthday

17 Data Types Graphics: Graphics fields are used to store pictures. Different graphics formats such as GIF or JPG may be used depending on the database Hyperlink: A hyperlink field is a special type of text field. In addition to storing text, the database will allow users to click on the hyperlink and open that URL in a browser window Boolean: Boolean fields can only contain one of two possible values. These are usually either true or false. Some databases use yes or no instead. It is possible to store a Boolean field in a single bit.

18 Validation Validation is when a database forces the user to enter data that meets a certain set of rules. If the data does not meet the rules – is invalid – the database rejects it There are a number of different types of validation check:  Presence check – ensures something has been entered  Unique check – ensures the value entered is different from every other instance of the field in the table.  Length check – restricts the number of characters that can be entered  Range check – ensures the value entered falls within a numerical range  Restricted choice – give the users a limited set of choices to pick from to prevent errors. Commonly used with look up tables for foreign keys

19 Questions – Data Types & Validation Answer questions in full sentences! 1. What is meant by the data type of a field? 2. Why do fields need to have a data type? 3. Describe in detail the information stored and how it is stored for four field types 4. Choose a suitable type or types of validation check to apply to the following fields. Explain your decision: a.A field containing test marks out of 20 b.A field containing mobile phone numbers – hint: mobile phone numbers contain 11 digits c.A field containing which house – Edinburgh, Fyvie or Cragievar – that a pupil belongs to d.The primary key field of a database e.A postcode field, where the field cannot be left blank

20 Database Operations Two operations to query the data in a database can be carried out – searching and sorting A simple search finds all the records in a database that match a criterion set on one field Comparison operators such as =, > and < are used to match the value in a given field for each record. For example: Cost < 0.10Matches all records where the value in the field Cost is less than 10 Name = “Alice”Matches all records where the value in the name field is Alice Name = “B*”Matches all records where the value in the name field begins with the letter B

21 Complex search A complex search allows several search criteria to included in a single search. The logical operators AND and OR are used to connect conditions together ANDThe values in the fields must match both conditions in order for the record to be found by the search ORThe values in the field only need to match one condition for the record to be found by the search Mark >=60 AND Mark <70Finds all test marks between 60 (inclusive) and 70 – all the B grades Grade = “A” OR Grade=“B”Finds grades that are either A or B. It finds both As and Bs.

22 A database sort puts the records, or results of a search, into order. A field can be specified as the basis for sorting. The sort can either be ascending (lowest value first) or descending (highest value first). For example: Sort by Name in ascending order The records will be displayed ordered by the Name field, starting at A and ending at Z. A secondary sort field can be specified. When the values in the primary sort field are the same, the secondary field will be used to differentiate between the records Searches and Sorts can be created in SQL. Structured Query Language is a scripting language that can be used to manipulate the information in databases

23 Identifying a sort You may be asked to identify how a database has been sorted. This will always be a sort on two or more fields The steps to identify a sort are: ◦ Identify the primary field for the sort – This should be the only field that the values go completely in order through the entire column. ◦ State if the primary field is sorted in ascending or descending order ◦ Identify groups of rows in the primary sorting field that have the same value ◦ Check each other column for evidence of sorting – only look at the rows with the same value in the primary sort field ◦ State the secondary sort field and if it is sorted in ascending or descending order

24 Identifying a sort Date is the only column that is in order for all the rows It is the primary sort field, in ascending order These are the groups of rows with the same value for date We have to check each group to see what order it is in So this database is sorted into date ascending order, then time ascending order

25 Questions – Database Operations Answer questions in full sentences! 1. Explain the difference between a simple and a complex search 2. Explain the difference between the AND and OR logical operators 3. Describe what each of the following complex searches will find: a.Year Group = 4 AND House = Edinburgh b.Favourite Subject = “Computing” OR Favourite Subject = “Maths” c.Gender = “M” AND Age >=12 AND Age <= 17 4. Explain when the secondary sort field will be used during a sort 5. Identify how the following table has been sorted:


Download ppt "N5 Databases Notes Information Systems Design & Development: Structures and links."

Similar presentations


Ads by Google