Ch.5: Introduction to databases Theory Notes Chapter 5 Introduction to databases Eng. Omar El Safty Eng. Mustafa El-Komy Ch.5: Introduction to databases Theory Notes 5.1 Data types 1. Numeric data Numeric data simply means numbers. Numbers come in a variety of different types: Integer • Positive or negative whole number • Examples: 12, 45, 1274, 1000000, -3, -5735 Real/Decimal • Positive or negative numbers with decimal/fractional parts • Examples: 1, 1.4534, 946.5, -0.0003, 3.142 Currency • Currency refers to real numbers that are preceded by a currency symbol • Examples: £12.45, -£0.01, €999.00, $5500. Percentage • Percentage refers to any number that is followed by a percent symbol • Examples: 100%, 25%, 1200%, -5%. 2. Alphanumeric/Text data • • Alphanumeric data refers to data made up of letters and numbers. Examples: DOG, "A little mouse", ABC123, enquiries@bbc.co.uk. 3. Boolean data • • Boolean data can only have two values. Examples: TRUE and FALSE, YES and NO, ON and OFF, Male and Female. 4. Date/Time data • Date/Time data is usually formatted in a specific way according to the setup of the computer and the user’s preferences. • • Date Examples: 25/10/2007, 12 Mar 2008, 10-06-08. Time Examples: 11 am, 15:00, 3:00 pm, 17:05:45. Eng. Omar El Safty 43 Eng. Mustafa El-Komy Ch.5: Introduction to databases Theory Notes Selecting data types When we input data to a computer, we must analyze it and select appropriate data types for each value. Student Name: Ben Smith Alphanumeric Student Number: 1234 Numeric Integer Date of Birth: 10 July 1998 Date/Time Year Group: 6 Numeric Integer Telephone: (0232) 744 6574 Alphanumeric Special Diet: Yes Boolean Exam Score: 78% Numeric Percentage Height: 1.67 Numeric Real Fees Paid: $ 1500 Numeric Currency The data type of a telephone number is Alphanumeric data as: • Telephone numbers often have spaces, dashes or any other symbol. • Telephone numbers may start with a zero (numeric data cannot start with a zero). • Telephone numbers are not used in arithmetic operations Eng. Omar El Safty 44 Eng. Mustafa El-Komy Ch.5: Introduction to databases Theory Notes 5.2 Definition of database A database is an organized collection of data related to each other. 5.3 Database terminologies Term Definition Examples Table A collection of related records Table of students For a student the fields could include: Field Field Name Record A column that contains one specific piece of information and has one data type • Student name • Student ID • Age • Address • Gender Title given to each field A row within a table that contains data about a Details (all information) of single item, person or event one student Primary Key Eng. Omar El Safty 45 Eng. Mustafa El-Komy Ch.5: Introduction to databases Theory Notes Primary keys Definition and features/characteristics: • • • • A primary key is a field that contains unique values Helps identify the record A primary key cannot be a null value Creates relationships 5.4 Database types Flat-file database Definition: Database where all the data is held in a single table. Example: Relational database Definition: • • • Contains more than one table linked to each other It uses relationships It makes use of foreign key Example: For this example, all the data about customers is held in one file, and all the data about jobs is held in another file. To create a connection between the two files, a relationship must be created Eng. Omar El Safty 46 Eng. Mustafa El-Komy Ch.5: Introduction to databases Theory Notes Foreign keys Definition and features/characteristics: • • • • It is a primary key in another table Enforces referential integrity A foreign key can have a null value Found in relational databases Example: 'Customer ID' field acts as the primary key in the customer file and the foreign key in the job file, thus enabling a relationship between the two tables. Relationships A relationship is a link or association between fields. The relationship between the tables can be: • one-to-one • one-to-may • many-to-many Similarities between relational databases and flat file databases: • • • Both use a primary key Both can create reports Both store data in records and fields in the table Eng. Omar El Safty 47 Eng. Mustafa El-Komy Ch.5: Introduction to databases Theory Notes Advantages of a relational database over a flat-file database: • • • • • • • • • Uses data integrity, which means no inconsistency in the data No duplication of data, so less data entry Saves time when entering data, as the user only has to input the data once Fewer errors are produced due to less data entry Saves storage space as data is only stored once Easier to add/modify/delete data Complex reports can be created Complex queries can be carried out Better security as some tables can be made confidential Disadvantages of a relational database over a flat-file database: • • • • • • • Takes more time to set up More complex than flat-file databases as more tables are used More complex to understand Sorting/Filtering of data is more complex Slower extraction of data Needs more processing power for complex queries Needs specialist personnel to set up the database Differences between Primary Key and Foreign Key: • • • Each table has one primary key, whereas a table can contain several foreign keys The primary key holds unique data, while the foreign key can be replicated in the table The primary key identifies the record, while the foreign key is used to link with the primary key of another table Eng. Omar El Safty 48 Eng. Mustafa El-Komy Ch.5: Introduction to databases Theory Notes 5.5 Data validation Definition and purpose: • • • An automated computer check Ensures that the data entered into a computer is sensible/reasonable Ensures the data entered fits the set criteria Validation check Description Example(s) In an online form, a person’s Presence check Checks if data is present and hasn’t been left blank telephone number may be a required field. So, if no data is entered, an error message will be produced. When registering a course in Lookup check Checks if value entered is available IGCSE, the session must be either in a limited set/list of items June, November or Jan. No other entry should be accepted. • Range check Checks whether numeric data is within given/acceptable values • Uses two boundaries • Checks whether numeric data is Limit check within given/acceptable values • Uses one boundary only To check if a student’s age is < 18 and > 0 To check if student’s age is < 18 (no lower boundary) If a field needs six digits, then Length check Checks if the input data contains inputting a five-digit or seven-digit the required number of characters number should cause an error message. Type check Format check Eng. Omar El Safty Checks that the input data has the appropriate data type A person’s age should be numeric integer not alphanumeric, for example. Checks the data is in a specific A date which should be in the form format or fixed pattern of dd/mm/yyyy, for example. 49 Eng. Mustafa El-Komy Ch.5: Introduction to databases Character check Theory Notes It checks that a string of characters does not contain any invalid characters or symbols. • A name would not contain characters such as % • A telephone number would only contain digits A validation check used in barcodes to validate the correctness of the Check digit barcode. This is done by adding an extra digit that is calculated from the other digits using some formula. Validating the correctness of a barcode 5.6 Data verification Definition and purpose: • Checks that the data on the original source document is identical to the data that you have entered into the system • Ensures that the data is copied/entered correctly Visual verification Definition: • • • Data is compared visually with the source document by a user The user is asked to confirm that the data entered is the same as the original If the user finds a difference, the data is re-entered Double data entry Definition: • • • Data is entered twice by the same person // by two different people A computer checks that both entries are equal If they are not equal, an error message requesting to re-enter the data is displayed Eng. Omar El Safty 50 Eng. Mustafa El-Komy Ch.5: Introduction to databases Theory Notes Similarities between visual verification and double data entry: • • • Both are used to check that data has been entered correctly Both ensure that the data has been transferred correctly Both are used to check the data against the original data Differences between visual verification and double data entry: • In visual verification the user compares the data, whilst in double data entry the computer compares the data • In visual verification the data is compared with the original data source visually, whilst in double data entry the data is compared with the previously entered data • In double data entry, data is entered twice by the user(s) Double data entry is different from Proofreading! Proofreading is reading through the document to check grammar and spelling mistakes without referring to the original source document. Eng. Omar El Safty 51 Eng. Mustafa El-Komy