Databases Tom Morgan.

Slides:



Advertisements
Similar presentations
Relational Database and Data Modeling
Advertisements

Organisation Of Data (1) Database Theory
Chapter 10: Designing Databases
Database Systems: Design, Implementation, and Management Tenth Edition
Data Management Design
The Relational Database Model:
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Mgt 20600: IT Management & Applications Databases Tuesday April 4, 2006.
Relational Databases What is a relational database? What would we use one for? What do they look like? How can we describe them? How can you create one?
Data at the Core of the Enterprise. Objectives  Define of database systems  Introduce data modeling and SQL  Discuss emerging requirements of database.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Software Development Unit 2 Databases What is a database? A collection of data organised in a manner that allows access, retrieval and use of that data.
Introduction to Databases and Database Languages
IST Databases and DBMSs Todd S. Bacastow January 2005.
PHASE 3: SYSTEMS DESIGN Chapter 7 Data Design.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
1 DATABASE TECHNOLOGIES BUS Abdou Illia, Fall 2007 (Week 3, Tuesday 9/4/2007)
2.3 Organising Data for Effective Retrieval
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
Data at the Core of the Enterprise. Objectives  Define of database systems.  Introduce data modeling and SQL.  Discuss emerging requirements of database.
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
Database Technical Session By: Prof. Adarsh Patel.
FatMax Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 LicenseCreative Commons Attribution-NonCommercial-ShareAlike 2.5.
1 Chapter 1 Overview of Database Concepts. 2 Chapter Objectives Identify the purpose of a database management system (DBMS) Distinguish a field from a.
Concepts and Terminology Introduction to Database.
CHAPTER 8: MANAGING DATA RESOURCES. File Organization Terms Field: group of characters that represent something Record: group of related fields File:
Database Management. ICT5 Database Administration (DBA) The DBA’s tasks will include the following: 1. The design of the database. After the initial design,
MIS 301 Information Systems in Organizations Dave Salisbury ( )
Lecture 2 An Overview of Relational Database IST 318 – DB Admin.
CODD’s 12 RULES OF RELATIONAL DATABASE
MIS 301 Information Systems in Organizations Dave Salisbury ( )
I Information Systems Technology Ross Malaga 4 "Part I Understanding Information Systems Technology" Copyright © 2005 Prentice Hall, Inc. 4-1 DATABASE.
Data Modelling. ICT5 Introduction Historical development with most organisations Small-scale origins Individual computers bought for particular applications.
Discovering Computers Fundamentals Fifth Edition Chapter 9 Database Management.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
1.file. 2.database. 3.entity. 4.record. 5.attribute. When working with a database, a group of related fields comprises a(n)…
Information Systems & Databases 2.2) Organisation methods.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Chapter 1Introduction to Oracle9i: SQL1 Chapter 1 Overview of Database Concepts.
Relational Database. Database Management System (DBMS)
Module 2: Information Technology Infrastructure Chapter 5: Databases and Information Management.
DataBase Management System What is DBMS Purpose of DBMS Data Abstraction Data Definition Language Data Manipulation Language Data Models Data Keys Relationships.
Databases Shortfalls of file management systems Structure of a database Database administration Database Management system Hierarchical Databases Network.
ITGS Databases.
 So far in ICT we’ve covered how data is entered into computers (data capture) and how it’s checked (validation and verification).  In this section.
Data resource management
+ Information Systems and Databases 2.2 Organisation.
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Concepts 2440: 180 Database Concepts Instructor:
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
Database Management Systems (DBMS)
Chapter 56 Relational Database Design Compiled by Eddie Moorcroft.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
©2003 Prentice Hall Business Publishing, Accounting Information Systems, 9/e, Romney/Steinbart 4-1 Relational Databases.
BSA206 Database Management Systems Lecture 2: Introduction to Oracle / Overview of Database Concepts.
Flat Files Relational Databases
Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall Chapter 9 Designing Databases 9.1.
CIS 250 Advanced Computer Applications Database Management Systems.
Sample Table Standard Notation Entity name in uppercase
Data The fact and figures that can be recorded in system and that have some special meaning assigned to it. Eg- Data of a customer like name, telephone.
FatMax Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 LicenseCreative Commons Attribution-NonCommercial-ShareAlike 2.5.
Databases Flat Files & Relational Databases. Learning Objectives Describe flat files and databases. Explain the advantages that using a relational database.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Database Planning Database Design Normalization.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Rationale Databases are an integral part of an organization. Aspiring Database Developers should be able to efficiently design and implement databases.
Chapter 4 Relational Databases
Chapter 2 Database Environment.
Database Management Concepts
Flat Files & Relational Databases
Presentation transcript:

Databases Tom Morgan

What is a Database? A collection of organised data Data has structure Can be paper-based More common to talk about electronic databases i.e. computer-based

Flat-File Database A flat file database is a simple database that stores all data in a single table. A flat file database can be stored in a text file, such as a tab-delimited file; a spreadsheet; or in a database file that contains one or more unrelated tables. Useful for simple lists: Address book CD collection But many problems... Data redundancy data duplicated in many different files. Makes data entry slower Uses disk space Data inconsistency same data held in different files has to be updated in each separate file when it changes. Program-data dependence Every computer program has to specify exactly what data fields constitute a record in the file being processed. Changes in data structure result in changes to programs Lack of flexibility Difficult and time-consuming to assemble the data from the various files and write new programs to produce the required non-routine reports. Data was not shareable If one department had data that was required by another department, it was awkward to obtain it.

Relational Database Management System (RDBMS) A more complex database that stores data in multiple tables that are interrelated. RDBMS benefits: Reduced redundancy Improved data consistency Improved data integrity Better security Program-data independence

Database Design A file is a collection of sets of similar data called records. Each piece of data within a record is called an item. Items are stored in fields. Database consists of a series of related files called tables. Table Records Fields Imagine a file of student details in school. Data held may include; Name, address, emergency contact, form, form teacher, form room, subjects studied... Each of these is a field, and the data placed in them in the item, So we have... A file, containing all the data about the students in the school Records, each has the same sort of contents and each one relates to a specific student Fields, which may have an item in them or not. Field ‘name’ will always have an item in it. ‘Additional notes’ may be blank. Blank fields can cause problems when interpreting the data at a later date. Does it mean that you have no information, or you have forgotten to enter the information? If information is unavailable it is better to provide a standard response – N/A or Unknown for example. Some fields may be unique. Could be possible that all students have different names – unlikely!! Fields stored can be used to mail merge letters for contacting a particular group - All people living in a specific village. Some field items will be repeated in record after record - Form name, room and teacher

Database Design contd... Field items could be of different length, and can cause problems... A file where all the records are of the same length is said to have fixed length records. Some fields are always the same length Postcode is always 7 characters Some fields may need to be 'padded out' so they are the correct length Surname - If 15 characters are stored then Jenkins would be stored as 'JENKINS        ' - 7 char + 8 spaces Advantage : Access is fast because the computer knows where each record starts. Disadvantage : Using Fixed length records, the records are usually larger and therefore need more storage space and are slower to transfer (load or save).

Variable Record Length One or more of the fields can be of differing lengths in each record. Advantages: the records will be smaller and will need less storage space the records will load faster Disadvantages: The computer will be unable to determine where each record starts so processing the records will be slower.

Storage Method 1 When the record is stored, each field has a field terminator byte stored at the end of it, and there is often a record terminator at the end of the whole record. The first record of the example would be stored as..... * is a field terminator % is a record terminator This record requires 33 bytes of storage... but each record will be a different size.

Storage Method 2 Each field starts with a byte showing the length of the field. The whole record starts with a byte giving the size of the record. The first record of the example would be stored as... This record requires 34 bytes of storage.. but again, each record would be a different size.

Database Structure Each record in a file must be identifiable and one field must be unique. Known as the Primary or Key Field. Terminology: File = Table Record = Tuples Field = Attribute

Normalisation Databases are collections of data arranged into related tables. There are lots of ways of arranging the data in tables and each arrangement can be given a label according to how it has been arranged These labels are called their Normal Form. Normalisation is the process undertaken to make sure a database has no redundant data or inconsistencies. Tables should be organised so that: No data is unnecessarily duplicated Data is consistent throughout the database The structure of each table is flexible enough to allow you to enter as many or as few items as you want to The structure should enable a user to make all kinds of complex queries relating data from different tables

1st Normal Form (1NF) "A table is in 1NF if it contains no repeating attributes or groups of attributes" e.g. A student can take several courses.        Each course has several students attending.         The relationship can be represented by an ER diagram: The attributes in these tables would look something like this: STUDENT (StudentID, StudentName, DoB, Gender) COURSE (CourseNumber, CourseName, LecturerID, LecturerName) Consider the problems of creating a relationship between these 2 tables... A link has to made between common fields... but there are no common fields! We could link the tables by copying an attribute from one into the other, but whichever attribute we pick, there will always be repeating attributes created,(which is unacceptable in 1NF!) as shown below... STUDENT (StudentID, StudentName, DoB, Gender, CourseNumber) No good - The student takes several courses, which one would be mentioned? COURSE (CourseNumber, CourseName, LecturerID, LecturerName, StudentID) No good - Each course has more than one student taking it. How about allowing space for 3 courses on each student record? STUDENT (StudentID, StudentName, DoB, Gender, Course1, Course2, Course3)    This is no good either - we have created a repeating attribute! The field, CourseNumber is repeated 3 times. The table is therefore not in first normal form. In standard notation, this would be represented by a line above the repeating attribute. To achieve 1NF we must make CourseNumber part of the Primary Key of the STUDENT table... STUDENT(StudentID, CourseNumber StudentName, DoB, Gender)  By grouping StudentID and CourseNumber together, we can uniquely identify each student and the courses they are taking without having any repeating attributes = 1NF.

2nd Normal Form (2NF) 2NF only applies to table that have a Composite Key! "A table is in 2NF if it is in 1NF and it contains no partial dependencies" At the moment, our tables are not in 2NF because they contain attributes that are only partially dependent upon the Primary Key... to be in 2NF, all attributes need to be wholly dependent on the Primary Key. All very well... but what does it mean? The Primary Key of our STUDENT table is a Composite Key, made up of both StudentID and CourseNumber. The attribute StudentName is dependent upon StudentID (One specific StudentID will refer to only 1 student) but it is in no way dependent upon CourseNumber (We cannot identify an individual student by a CourseNumber). This makes it only partially dependent on the Primary Key, and therefore not in 2NF. To achieve 2NF we need to introduce a 3rd table to link the two entities: STUDENT(StudentID, StudentName, DoB, Gender)  COURSE (CourseNumber, CourseName, LecturerID, LecturerName) STUDENT_TAKES (StudentID, CourseNumber)

3rd Normal Form (3NF) "A table is in 3NF if it contains no non-key dependencies" The COURSE table contains an attribute for LecturerID and also one for LecturerName.  LecturerName is dependent on LecturerID (not on CourseNumber)... We need a new table for the entity LECTURER! STUDENT(StudentID, StudentName, DoB, Gender)  COURSE (CourseNumber, CourseName, LecturerID) STUDENT_TAKES (StudentID, CourseNumber) LECTURER (LecturerID, LecturerName) This is the optimum way of holding this data without any duplication. All tables in a Relational Database should be in 3NF!

Methods & Tools Each table contains one special attribute by which tuples can be identified because it is unique Primary key – shown by underlining its reference within the bracket of attributes A Primary Key is one or more attributes which uniquely identify an entity occurrence. Sometimes a single attribute is not sufficient to identify each occurrence of an entity uniquely. In these instances we must combine two or more attributes to create a Composite Key. For example, a person's name by itself will not necessarily be enough to identify an individual. A person's name combined with their address may be more appropriate.   A key in one table that occurs in another table is called a Foreign Key - Used to link 2 tables together Terminology: File = Table Record = Tuples Field = Attribute

Entity Definitions Every entity has a name and a Primary Key. Most entities will also have a number of non-identifying attributes. The convention used for defining attributes is shown below. EntityName (Identifying Attribute1, NonIdentifying Attribute1, .....) The name of the entity is followed by a list of its attributes in brackets. The identifying attribute(s) (Primary / Composite Key) comes first and is underlined. When all the attributes are not yet known this can be shown by a row of dots.

Entity Relationship Diagram An entity-Relationship (ER) diagram shows what information is stored and how it is related i.e. it models the structure of the data. There are 3 main concepts in an ER Diagram: Entities - Things, usually nouns e.g. 'Student' Attributes - Properties of things e.g. 'Name', 'StudentID' Relationships - Connections between things e.g. Student 'studies' Course An entity is a real world object about which data is to be recorded. Attributes are properties, or characteristics, of entities. Relationships are associations between entities. An ER model consists of: A diagram showing entities and the relationships between them. Formal descriptions of each entity in terms of its attributes. Descriptions of meanings of relationships. Descriptions of any constraints on the system and of any assumptions made.

Entity Relationship Diagram Contd... Diagram Conventions for an ER Diagram Entities are shown as rectangles with the name of the entity inside.   When choosing an entity name: Use singular nouns e.g. 'Student' not 'Students'. Start with an upper case letter and concatenate words e.g. DegreeScheme. Choose distinct names. Three degrees of relationship can be represented: A one-to-one relationship 1 : 1 A one-to-many relationship 1 : n A many-to-many relationship m : n Example: Name

Databases A database can very quickly become complicated. They require something to control it and to control access to it. It needs to control the amending of data to ensure that all the rules remain unbroken. Addition & deletion of data must also be controlled. This software is called Database Management System. Database Management System Data storage, retrieval and update DBMS must allow users to store, retrieve and update information as easily as possible, without having to be aware of the internal structure of the database. Creation and maintenance of the data dictionary Managing the facilities for sharing the database ensure that problems do not arise when two people simultaneously access a record and try to update it. Backup and recovery provide the ability to recover the database in the event of system failure. Security handle password allocation and checking, and the ‘view’ of the database that a given user is allowed.

Database Management System Includes a piece of software called Data Description Language DDL. DDL is used to define the tables in the database, including; Data types Data structures within the database Any constraints on the data The design that is created is called a schema. Each user of the database will use it for different things, will be allowed to see different parts and will be given their own subschema to give the rules of how they see data. Users of the database will be given different rights: Db Admin allocates users to groups of one or more & assigns each group a set of privileges or permissions. Permissions determine whether user can view / modify / execute / update. Each user / group has own username Each user has individual password (can & should change regularly) Some will involve manipulating data (amend/delete/insert new data). Done using a tool called a Data Manipulation Language – DML.

Contd... Manipulation techniques of a DBMS can simplify the use of the DDL & DML Query By Example (QBE) The DBMS maintains a file of descriptions of the data and the structure of storage known as the data dictionary. Data Dictionary The data dictionary is a ‘database about the database’. It will contain information such as: What tables and columns are included in the present structure; The names of the current tables and columns; The characteristics of each item of data, such as its length and data type; Any restrictions on the value of certain columns; The meaning of any data fields that are not self-evident; e.g. a field such as ‘course type’; The relationships between items of data; Which programs access which items of data, and whether they merely read the data or change it. Various tools allows the DBMS to present differing views of the data held within the database.

Contd... Internal level – 1st Level View of the entire database as it is stored in the system Level at which data is organised according to random access, indexed, sequential... It is hidden from the user by the DBMS Conceptual level – 2nd Level Gives a single, usable, view of all the data on the database External level – 3rd view Where data is arranged according to user requirements and rights Different users will get different views of the data