Download presentation
Presentation is loading. Please wait.
Published byMeagan Wilkinson Modified over 8 years ago
2
BTEC NCF IT Unit 02 Creating Systems to Manage Information Lesson 05 – Data Types Mr C Johnston
3
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
4
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!
5
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)
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 ▫ 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 2016 - 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 ▫ Offers more precision for storing prices 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 EntityKeyAttributeData typeSizeValidation STUDENTPrimary Foreign StudentID Title First Name Second Name CityID Post Code DOB ApplicationDate AutoNumber Text Number Text Date/Time Auto 4chars 15chars 20chars Long Integer 8chars Short date 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:
16
Activity 1)For each of the scenarios drawn as part of the ERD exercise create a data dictionary for each entity Think carefully about the use of keys to ensure that the relationships will work 2)Compile both the ERD and DD into single page LDM for each scenario. 3)Create a LDM 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.
17
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
18
Methods of Validation 1 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!! Presence check Is the field allowed to be left empty or must the user enter something e.g. [surname] - required = yes, [email] – 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. 6754 is calculated by: 365 days a year * 18 years + 4 extra days for leap years 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.
19
Methods of Validation 2 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) 000000 (allows 02476 123123 and 07957 123123) 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 Default values Used to suggest a value for a field which is common or default e.g.[city] – default = coventry [orderDateTime] – default = now() 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: http://office.microsoft.com/en-us/access-help/control- data-entry-formats-with-input-masks- HA010096452.aspx http://office.microsoft.com/en-us/access-help/control- data-entry-formats-with-input-masks- HA010096452.aspx
20
Data Dictionary With Validation For each field within your data dictionary think about which validation rule could be added – remember to add a validation text column to explain the rule simply for users EntityKeyAttributeData typeSizeValidation STUDENTPrimary Foreign StudentID Title First Name Second Name CityID Post Code DOB ApplicationDate AutoNumber Text Number Text Date/Time Auto 4chars 15chars 20chars Long Integer 8chars Short date Required = yes “Mr” OR “Mrs” OR “Miss” OR “Ms” Required = yes Looked up in [city] Required = yes <=date()-5478 Required = yes Default Value = now() >=Date()
21
Activity 1)For each of the data dictionaries created earlier add appropriate validation rules and validation text to attributes which need them 2)Using Microsoft Access create some of the logical data models you have been designing over the last few lessons EntityKeyAttributeData typeSizeValidation RuleValidation Text Validation Text – a friendly message which alters the user if a validation method has been broken and tips on how to solve the error
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.