Presentation is loading. Please wait.

Presentation is loading. Please wait.

BTEC NCF IT Unit 02 Creating Systems to Manage Information Lesson 05 – Data Types Mr C Johnston.

Similar presentations


Presentation on theme: "BTEC NCF IT Unit 02 Creating Systems to Manage Information Lesson 05 – Data Types Mr C Johnston."— Presentation transcript:

1 BTEC NCF IT Unit 02 Creating Systems to Manage Information Lesson 05 – Data Types
Mr C Johnston

2 Learning Outcome For more complex situations produce ERD’s correctly resolving any many-to-many relationships Understand the use of different data types and the selection of field sizes Create detailed data dictionaries for ERD’s by selecting appropriate datatypes, fields sizes for attributes and using keys correctly

3 Revision of Terms An entity is a person, place or object
More commonly in English its know as a noun E.g a student at college could be an entity Entities have attributes E.g a student has a name, address, phone number etc. Each entity needs a unique identifier if it is to be used in a relational database – this is known as a primary key in database land!

4 Revision of Terms Entities have relationships with one another
There are three types of relationships One to One, One to Many, Many to Many One to Many relationships are the only type allowed - the other two types need resolving Relationships between entities are shown in an Entity Relationship Diagram (ERD) This forms one component of the Logical Data Model (LDM) When setting up one to many relationships the primary key from the entity on the one side of the relationship goes and lives as a foreign key in the entity on the many side BTEC requires you to draw an EXTENDED ERD which clearly shows the attributes including primary and foreign keys

5 Review

6 Starter Download and complete the ERD Exercise Worksheet.
Some of the scenarios have multiple entities so be careful. HINT: Drawing a diagram with the many-to-many relationships in to start with and then a second diagram with them resolved may be easier

7 Constructing Database Tables
A database table is made up of an entity set Each database table needs a name We normally use the name given to the entity It should be written in capitals Tables need attributes, which are found during the process of normalisation Each attribute needs a data type and some form of validation

8 Attribute Data Types Attributes must be one of the following data types: Text or String, Numeric, Date and Time, Currency, Boolean or Logical, AutoNumber. Data types have different sizes to choose from – you need to pick an appropriate size as well as data type for each attribute, Some common sizes for each data type are given on the next few slides.

9 Attribute Data Types Short Text or String Long Text or String
Consists of a sequence of any characters, Default size and limited to 255 characters Always change the size to a realistic amount to cut down on wasted space Long Text or String New in access previously memo in earlier versions of Access For longer text requirements it can store up to about a gigabyte of text, even though controls on forms and reports can only display the first 64,000 characters.

10 Attribute Data Types Number Byte: 0 to 255 Integer: -32,768 to 32,768
Long Integer: 2,147,483,648 to 2,147,483,647 Single: small decimal numbers (7dp) Double: medium decimal numbers (15dp) Decimal: large decimal numbers (28dp)

11 Attribute Data Types Date and Time General Date – 19/06/1994 17:34:23
Long Date – 19 June 1994 Medium Date – 19 – JUN - 94 Short Date – 19/06/1994 Long Time – 17:34:23 Medium Time – 05:34 PM Short Time – 17:34

12 Attribute Data Types Currency Boolean / Logical
Offers more precision for storing prices State the number of decimal places within the size colum Boolean / Logical True, False On, Off Yes, No

13 Just a thought…. MATHS PROBLEM!!!
Each character takes up 1 byte of storage Short Text allows for 255 characters therefore it reserves by default 255 bytes of space A phone number has 11 characters. If we store 1306 phone numbers in a database using the default small text setting how much space is reserved unnecessarily and is wasted?

14 Using The Correct Data Types
You must ensure that the correct data type is chosen for an attribute The larger the maximum value the more memory in the database is taken up e.g phone numbers don’t need to be calculated with so can be stored as text Text fields by default allow 255 characters

15 The Data Dictionary The data dictionary (DD) is a table used to document entities, A data dictionary along with an ERD makes up a logical data model (LDM) A data dictionary for a student may look like this: Entity Key Attribute Data type Size Validation STUDENT Primary Foreign StudentID Title First Name Second Name CityID Post Code DOB ApplicationDate AutoNumber Text Number Date/Time Auto 4chars 15chars 20chars Long Integer 8chars Short date

16 BTECs Data Dictionary Template
Here is the 2018 template which BTEC expected learners too use Table Name Description Field Name Data Type Primary/ Composite Key (Y/N) Foreign Key (Y/N) Field Size (if applicable) Format/ Input Mask (if applicable) Validation (if applicable) What are the differences between the official BTEC data dictionary and mine?? What is the difference between a table and an entity and an attribute and a field name?

17 Activity For each of the scenarios drawn as part of the ERD exercise create a data dictionary for each entity Make sure you use the official BTEC data dictionary template (ignore last two columns for now) Create an extended ERD and Data Dictionary for customers wishing to book a ferry crossing. Each crossing runs several times a time and has one ferry assigned to it. A ferry could be responsible for more than one crossing. Table Name Description Field Name Data Type Primary/ Composite Key (Y/N) Foreign Key (Y/N) Field Size (if applicable) Format/ Input Mask (if applicable) Validation (if applicable)

18 Ensuring Data Correctness
Keeping data integral is part of the job which the DBMS plays There are two methods to do this: Validation Ensuring data is within the right context Access provides lots of methods for this Verification Ensuring data is correct Access doesn’t provide any methods for this

19 Methods of Validation1 Format check Presence check Range check
Now() is a function which gives the current system date and time… useful for constructing validation rules, queries, forms and reports in Access. Other useful functions include: Date() which only gives the date and Time() which just gives the time. Format check Usually controlled by the data type and size selected e.g. If [price] field was set as an integer it would not work properly as the prices entered would have to be whole numbers!! Could specify required characters though e.g. [ ] must and . Presence check Is the field allowed to be left empty or must the user enter something e.g. [surname] – required = yes / is not null, [ ] – required = no Range check What are the range of numerical values allowed to be entered e.g. [price] - >= 0 AND <=1000, [order] >= Now() If customers have to be over 18: [DOB] <= (Date()-6754) 6754 is number of days old you would be if 18. So we take this away from current date to check the DOB is allowed is calculated by: 365 days a year * 18 years + 4 extra days for leap years

20 Methods of Validation2 Picture check / Input mask List of valid values
Constructing input masks can be tricky – L is for mandatory letters (A-Z), ? is for optional letter (A-Z), 0 is for mandatory numbers (0-9), 9 is for optional numbers (0-9). For full details see: Picture check / Input mask Used to check if the data entered looks like a defined pattern of text and numerical characters. Suitable for post codes (can be awkward) and phone numbers e.g. [postCode] – LL0 0LL (allows CV1 5NL but B1 5NL and CV10 5NL not allowed!!) [phoneNumber] – (00000) (allows and ) List of valid values Limit the values to only those on a defined list of from another table e.g. [gender] - “male” or “female”, [carID] – looked up from [CAR] limit to list = “yes” Default values Used to suggest a value for a field which is common or default e.g. [city] – default = coventry [orderDateTime] – default = now()

21 Data Dictionary With Validation
For each field within your data dictionary think about which validation rule could be added Table Name  tblSTUDENT Description  Contains student personal data Field Name Data Type Primary/ Composite Key (Y/N) Foreign Key (Y/N) Field Size (if applicable) Format/ Input Mask (if applicable) Validation (if applicable)  StudentID Autonumber N  Title Short Text  4 chars Is Not Null / Required = “yes” “Mr” OR “Mrs” OR “Miss” OR “Ms” FirstName  15 chars Is Not Null / Required= “yes” Surname 20 chars CityID Number Y Long Integer Looked up in [CITY] limited to list=“yes” Postcode 8 chars L?09 0LL DOB Date/Time Short Date DD/MM/YY <=date()-5478 ApplicationDate Default value =now()

22 Data Dictionary Rules1 The dictionaries should include:
clear table names using the standard naming convention of tbl followed by the table name a consistent approach to the naming of fields eg no spaces, spaces, camel case etc data types for each field Particular care should be applied to Date/Time and Number fields it is expected the examiners will be able to discern the format of the date: short/medium/long monetary amounts should be currency with the number of decimal places specified integer numbers do not need decimal places specified decimal numbers should have a size (single, double, decimal stated and number of decimal places The data types for foreign keys should match their primary key eg Autonumber -> number, short text->short text, number- >number

23 Data Dictionary Rules2 Validation
length checks (field sizes), these should be appropriate and only applied to text fields, format checks (input masks or validation rules), these should be appropriate presence checks – primary key fields are required by default so should not be specified range checks – read scenario where could be applied value lookups - repeating attributes that are foreign keys should be looked up in the primary table. Gender and titles could be looked up in an internal lookup list Clear indication of the primary and foreign keys

24 Data Dictionary Common Errors
Standard naming conventions were not used Field names were inconsistent, spaces, no spaces etc Data types were incorrect, decimal places were not specified, date formats not Specified, lookup wizard specified as a data type etc Field sizes were not sensible Validation was vague eg ‘presence check’ as opposed to is not null Table lookup as opposed to table lookup to tblBand limit to list = yes Validation was not sensible eg value lookups used on foreign keys, presence checks on primary keys Input masks/format checks were incorrect Primary and/or foreign keys had not been specified or were incorrect.

25 Activity For each of the data dictionaries created earlier add appropriate validation rules to attributes which you think need them – remember to use the official BTEC template Using Microsoft Access practice creating some of the logical data models you have been designing over the last few lessons Table Name Description Field Name Data Type Primary/ Composite Key (Y/N) Foreign Key (Y/N) Field Size (if applicable) Format/ Input Mask (if applicable) Validation (if applicable)

26 Homework Consider this scenario
Customers can book ferry crossings. Each crossing runs several times a time and has one ferry assigned to it. A ferry could be responsible for more than one crossing. Create an extended ERD and Data Dictionary for the scenario and upload you answer to Google Classroom Make sure you use the official BTEC template Table Name Description Field Name Data Type Primary/ Composite Key (Y/N) Foreign Key (Y/N) Field Size (if applicable) Format/ Input Mask (if applicable) Validation (if applicable)


Download ppt "BTEC NCF IT Unit 02 Creating Systems to Manage Information Lesson 05 – Data Types Mr C Johnston."

Similar presentations


Ads by Google