Chapter 7. Databases
Chapter 7. Databases
Lecture # 18-19
1
Outlin
Introduction es
Chapter 7: Traditional File Processing System
Limitations of Traditional File
Processing Systems
Databases
Database Management System
Advantages of DBMS
Types of Database
MS Access
Database Design in MS Access
Introduction
• A collection of logically related data organized to be accessed, managed and
updated easily.
• Small data collection or a large scale database.
• Used for various purposes including:
Storing internal data
Analyzing the market
Analyzing users’ interest
Discovering patterns in data and more.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 3
Introduction
Data
• Facts concerning objects and events.
• A salesperson’s data:
Names
Addresses
Phone numbers
Items
Prices and more.
• Numeric data
• Textual data
• Graphic data (Pictures and videos)
• Qualitative data
• Quantitative data.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 4
Introduction
Information
• Structured / processed data.
• Meaningful in some context.
• Well organized data on the basis of which an organization can take some
decision and can discover useful patterns in it.
Data Information
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 5
Introduction
Metadata
• Data about data.
• Describes the characteristics and context of data.
• The primary mechanism to provide the context for data.
• Examples:
Data type
Length
Maximum/minimum values
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 6
Traditional File Processing System
• Spreadsheets, word processing applications.
• A group of files that store data of an organization.
• Manual/computer based filling systems.
• All the departments have to maintain their own sets of files.
Limitations
• Duplicate data; complex and hard to manage.
• Separate sets of files for each department or organization.
• Limited data sharing.
• Hard to develop and maintain.
• Excessive program maintenance.
• Less security.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 7
Database Management System
• A computer software for creating and maintaining databases.
• A systematic way to create, retrieve, update and manage data.
• An interface between the database and the user.
Advantages
• Data Sharing
A centralized database, visible to every user and department.
• Concurrency
Multiple users can work with the database to add, update and update data.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 8
Database Management System
Advantages (continued…)
• Data Integrity
Consistent, accurate and trustworthy data.
• Data Quality
Improved data quality by specifying integrity constraints i.e. rules that can’t be violated
by database administrators.
• No Redundancy
Data is recorded in a centralized database accessible from everywhere.
Course Customer
Sales
Building man
Exam
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 10
Database Design Concepts
Attributes
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 11
Database Design Concepts
Relationships
Many to one
Many to many
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 12
Database Design Concepts
Entity Relationship Diagram
• A detailed logical representation of the data in an organization.
Entities
Relationships among entities
Attributes of the entities and relationships.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 13
Database Design Concepts
Relation
• A named, two dimensional table of data with:
A set of named columns (representing attributes)
Arbitrary number of unnamed rows (representing data values for a single entity)
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 14
Database Design Concepts
Table
• A collection of data held in a structured format within
a database.
• Vertical columns, identified by names.
• Horizontal rows, holding data for a single entity.
• Similar to relation with some differences:
Metadata associated, e.g. constraints
May have duplicate values unlike relation.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 15
Database Design Concepts
Record
• A complete set of information, relevant to a specific entity.
• Also called row; comprised of a single row in a table.
• Example:
The information (values against each attribute) for a specific student.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 16
Database Design Concepts
File
• A related collection of records.
• Example:
A collection of the records of all the students enrolled in a course.
Field
• A data structure for a single piece of data.
• Example:
Customer_ID, Name, Address, Phone_no are some of the fields in the table
Customer in an organization’s database.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 17
Database Design
Conceptual Database Design
• Output:
Entity relationship model, comprised of entities and their relationships
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 18
Database Design
Logical Database Design
• An extended version of the conceptual design:
Entities, their attributes and the relationships.
Primary keys (that uniquely define entities of an entity type).
Foreign keys (used to relate two tables).
Redundancy and other anomalies removed by Normalization.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 19
Database Design
Physical Database Design
• The logical database design is converted into a detailed design.
• Data types and lengths etc. of the attributes.
• The output is a design ready to be implemented.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 20
Types of Database
Flat File Database
• Files with no structured relationships among the records.
• Data is stored in a single table.
• Useful for storing small amount of records.
• Example: Spreadsheets.
Embedded Database
• Runs within an application rather than a separate database application.
• Integrated with program that needs to store data.
• Hidden from the user, requiring little or no maintenance.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 21
Types of Database
Distributed Database
• A set of interconnected databases located at different locations.
• Logically a single database.
• Data is accessed and modified with the help of a network.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 22
Types of Database
Centralized Database
• Located and maintained on a single location.
• Accessible from different locations via a network.
Knowledge Base
• Stores complex information used by computer systems.
• Structured or unstructured data.
• Examples:
Expert system, which uses knowledge base containing facts about a specific field.
Hypertext Database
• Used to organize large, dissimilar information.
• No regular structure, different from commonly used databases.
• Example:
Databases for maintaining encyclopedias.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 23
Types of Database
Operational Databases
Online Database
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 24
MS Access
• A DBMS, part of the MS Office suite.
• Lightweight and easy to use tool for designing database.
• Not suitable for designing large scale databases.
• Used to design and maintain small scale databases.
• Key features:
Creating databases
Creating tables
Creating relations
Data validation
Creating forms
Creating Queries
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 25
Database Design in MS Access
Creating Database
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 26
Database Design in MS Access
Creating Tables
• Navigate to Create tab on the ribbon and click
Table.
• A table “Table 1” will be created. Right click on it
and click “Save”.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 27
Database Design in MS Access
Creating Tables (continued…)
• Each table is created with one field, the ID.
• Right click it and rename to something relevant to the table, e.g. Student_ID.
• ID field should be “Auto Number” and “Unique” as it is the primary key.
• This is done by selecting the field and navigating to the FIELDS tab on the
ribbon.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 28
Database Design in MS Access
Creating Tables (continued…)
• To add a new field, click on “Click to Add” and select a suitable datatype, e.g.
“Short Text” for the field Name.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 29
Database Design in MS Access
Inserting Data into Tables
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 30
Database Design in MS Access
Data Validation
• To restrict the user not to enter invalid data.
• E.g. currency and price can’t be negative, a field can accept only letters etc.
• Achieved by the use of validation rules.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 31
Database Design in MS Access
Validation Rules
• Example, validation rule for email field:
Is Null OR ((Like "*?@?*.?*") AND (Not Like "*[ ,;]*"))
Where “Is Null” means the field can be empty.
• Commonly used validation rules:
To do….. Validation Rule
Accept letters only Is Null OR Not Like "*[!a-z]*"
Accept digits only Is Null OR Not Like "*[!0-9]*"
Accept digits and letters only Is Null OR Not Like "*[!((a-z) or (0-9))]*"
Accept a string of exactly 5 characters Is Null OR Like "?????"
Accept a value of exactly 4 digits Is Null OR Like "####"
Accept positive numbers only Is Null OR >=0
Accept date that is not future date Is Null OR <= Date()
Accept only “Male” and “Female” Is Null OR "Male" OR "Female"
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 32
Database Design in MS Access
Creating Query
• To manipulate data in the database, e.g. to update a field or delete a record.
• Example: Update student name in the first record.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 33
Database Design in MS Access
Creating Query (continued…)
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 34
Database Design in MS Access
Creating Forms
• An object used to create user interface for the database.
• Used to access and view data from one or more tables in a database.
• Procedure:
Create Form Wizard
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 35
Database Design in MS Access
Creating Forms (continued…)
On the next screen, select a layout for the form.
Give the query a name before finishing.
In Form View, the output would be something like this.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 36
Database Design in MS Access
Creating Reports
• An object used to display data from the database.
• Pick data from one or more tables using a query and then create a report.
• Example:
A report containing names, addresses and phone number of students.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 37
Database Design in MS Access
Creating Reports (continued…)
The report opens in Layout mode where its layout can be changed.
Switch to report view and you will see an output like this.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 38
Database Design in MS Access
Importing Tables to Database
• Import wizard is used to import tables etc.
from a .mdb or .accdb database.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 39
Database Design in MS Access
Importing Tables to Database (continued…)
• Select the tables, queries and forms etc. that are to be imported into the
database.
• Click OK to finish import. The selected items should appear in your database.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 40
Database Design in MS Access
Linking Tables with Database
• To have one or more tables in multiple databases.
• The tables are stored in a single database and are linked to as many
databases as needed.
• Eliminates the need to enter or update the same data multiple times.
• Procedure:
Similar to importing tables to database.
Introduction To Computer & ICT – by Dr. Rahman Ali & Asmat Ali 41
References