ميحرلا نمحرلا هللا بسم
Information Technology Course
Introduction to Database
What is data?
• Data is made up of text, numbers, images and in some cases sounds
which can be processed or stored by a computer. By itself data might
meaningless. In order to understand it, it needs to be interpreted (or
processed) to become information.
• Information is the meaning given to data by the way in which it is
interpreted.
What is data?
• To illustrate the difference, Ahmed, 2500 and 30 examples of data.
But if we were able to interpret them as the name of a salesman,
Ahmed, his annual basic salary of 2500 EP and his age of 30 years, it
would assume more meaning and could be called information.
Alternatively, the same data could be interpreted in another way.
• It is often helpful to think of data as the raw ingredients of a recipe
which when processed by differing techniques produce different
results.
What is a database?
A simple definition of a database is:
“A database is a collection of related, logically coherent data
which can be used alone, or combined / related to other data
to provide answers to the user’s question. .”
In normal daily life we make frequent use of databases, and probably
don’t realize it.
Databases touch all aspects of our lives
Examples:
Banking: all transactions
Airlines: reservations, schedules
Universities: registration, grades
Sales: customers, products, purchases
Manufacturing: production, stocking, orders
Human resources: employee records, salaries, ..……
Scientific data such as biology, etc.
Spatial data such as maps, travel networks,
E-commerce : Amazon.com, etc.
?
Why Study Databases??
Usually data is too large to fit into main memory,
and often used by many users
Datasets increasing in diversity and volume.
Digital libraries, interactive video, Human Genome
project
Traditional File Processing Sucks
File Processing:
Data is organized, stored, and processed in
independent files of data records
Problems of File Processing
Data Redundancy –
duplicate data requires
update to many files
Lack of Integration –
data stored in
separate files
hard to combine data
Data Dependence –
changing the file format requires changing the program…
Database Management Approach
Consolidates data records into one CENTRAL
database that can be accessed by many different
application programs.
Advantages of databases
1) Reduce data redundancy
2) Increase data consistency (If the same data is stored in more
than one place, then any changes in the data need to occur in
all places that data is stored = updating Data)
3) Increase data integrity and independence from applications
programs
4) Reduce data access , storage, and retrieval costs through use
of host and query languages
5) Improve data security
Database Management System (DBMS)
Definition:
A Database Management System is a software package/system
that defines, creates and manipulates a database.
The DBMS also allows controlled access to data in the
database.
A DBMS is a combination of five components: hardware,
software, data, users and procedures
Database Management System (DBMS)
Hardware
The hardware is the physical computer system that allows
access to data.
Software
The software is the actual program that allows users to access,
maintain and update data. In addition, the software controls
which user can access which parts of the data in the database.
Data
The data in a database is stored physically on the storage
devices. In a database, data is a separate entity from the
software that accesses it.
Database Management System (DBMS)
Users
In a DBMS, the term users has a broad meaning. We can divide
users into two categories: end users and application programs.
• End users - Normal user and Database Administrator
• Application programs
Procedures
The last component of a DBMS is a set of procedures or rules
that should be clearly defined and followed by the users of the
database.
Database System ≡ DBMS + Database
Database architecture
Internal Level
determines where data is actually
stored on the storage devices.
This level deals with low-level
access methods and how bytes are
transferred to and from storage
devices.
In other words, the internal level
interacts directly with the hardware.
Database architecture
Conceptual Level
defines the logical view of the data.
The data model is defined on this
level, and the main functions of the
DBMS, such as queries, are also on
this level.
The DBMS changes the internal view
of data to the external view that users
need to see.
The conceptual level frees users from
dealing with the internal level.
Database architecture
External Level
interacts directly with the user
(end users or application
programs).
It changes the data coming from
the conceptual level to a format
and view that is familiar to the
users.
Database models
A database model defines the logical design of data also describes
the relationships between different parts of the data.
In the history of database design, three models have been in use:
• Tree database model
• Network database model
• Distributed database model.
• Relational database model
Database models
Hierarchical (Tree) database model
In the hierarchical model, data is organized as an upside down
tree.
Each entity has only one parent but can have several children.
At the top of the hierarchy, there is one entity, which is called
the root.
Database models
Network database model
In the network model, the entities are organized in a graph.
Some entities can be accessed through several paths
Database models
Relational database model
In the relational model, data is organized in two-dimensional tables called
relations. It is the most popular model.
Each column within a table defines the fields, while each row defines the
records.
The tables or relations are related to each other.
For examples information about employees can be held in one table, while
information about salaries can be held in another separate table.
Database models
Database models
Distributed database model
It is not a new model. It is based on relational model.
The data are stored on several computers that communicate
through the Internet or some private WAN.
Data are either fragmented, with each fragment stored at one
site, or data are replicated at each site.
• Fragmented distributed databases
• Replicated distributed databases
Relational database model
Relations(Tables)
A relation in an RDBMS has the following
features:
Name: Each relation should have a name
that is unique among other relations.
Attributes: Each column in a relation is
called an attribute.
Tuples: Each row in a relation is called a
tuple. A tuple defines a collection of attribute
values.
“ An example of a relation “
Database Example
A set of relations(tables) form a database
Orders
OID CID PID Quantity
001 508 199 500,000
002 508 201 2
003 510 201 1
Customers Products
CID FName LName Address PID Description Cost
508 Eric Breimer ... 199 vitamin c $45.99
509 Andrew Zych ... 200 Tooth Paste $2.58
510 Greg Smith ... 201 Hair Gel $5.99
Databases
But, databases are not just a set of tables
Orders
OID CID PID Quantity
001 508 199 500,000
002 508 201 2
003 510 201 1
Customers Products
CID FName LName Address PID Description Cost
508 Eric Breimer ... 199 vitamin c $45.99
509 Andrew Zych ... 200 Tooth Paste $2.58
510 Greg Smith ... 201 Hair Gel $5.99
A database also includes relationships
between the different tables
Concepts Related to Tables of a database
What is a primary key?
• Primary key is made up of one or more fields that uniquely identify
each record in your table and provide the following advantages:
The primary key is often used in establishing relationships.
Duplicate records are not allowed.
A primary key can be made up of one or more fields.
Concepts Related to Tables of a database
What is a Foreign Keys?
Foreign keys enforce
referential integrity by
completing an association
between two entities.
Duplicate records are
allowed.
EX1: A part of relational database represents a company
EMPLOYEES
Employee_name ID Birth_date Gender Dept_code Job_grades
Record
SALARIES DEPARTMENTS
ID Salary Dept_code Dept_name
EX2: A part of relational database represents a university
DEPARTMENTS PROFESSORS
Dept_Code Dept_Name Prof_ID Prof_Name Dept_Code Course_No
COURSES STUDENTS
Course_No Course_Name Dept_code Prof_ID Stud_ID Stud_Name Course_No
Types of Relationships
ThingA ThingB
One to One Relationship
Examples? Man Woman
Analysis Technique Married
Consider ThingA and ThingB
Can ThingA be related to more than one ThingB?
Can ThingB be related to more than one ThingA?
If the two answers are NO, then it is a one to one
relationship.
Types of Relationships
Student
Faculty Student
One to Many
Student
Examples?
Advises
Analysis Technique
Get Advisement
Consider ThingA and ThingB
Can ThingA be related to more than one ThingB?
Can ThingB be related to more than one ThingA?
If only one answer is yes, then you have a one to many
relationship
student takes course
Types of Relationships Student
Course Student
Student
Many to Many Course
Examples? Student
Analysis Technique course has a student
Consider ThingA and ThingB
Can ThingA be related to more than one ThingB?
Can ThingB be related to more than one ThingA?
If the answers are yes and yes, then the relationship is
many to many.
OPERATIONS
ON
RELATIONS
Operations on relations
In a relational database, we can define several
operations to create new relations out of the
existing ones.
Basic operations:
Insert Delete
Update Select
Project Join
Union Intersection
Difference
Operations on relations
Each operation is described as defined in the
database query language SQL (Structured
Query Language).
Structured Query Language (SQL) is the language
standardized by the American National Standards
Institute (ANSI) and the International Organization
for Standardization (ISO) for use on relational
databases.
It is a declarative rather than procedural language,
which means that users declare what they want
without having to write a step-by-step procedure.
Insert operation
• Insert Operation: Inserts new tuple into the relation
• insert into RELATION-NAME values ( … , … , … )
• insert into COURSES values ( “CIS52”,”TCP/IP”, 6 )
“An example of an insert operation”
Delete operation
• Delete Operation: Deletes tuple from the relation
• delete from RELATION-NAME where criteria
• delete from COURSES where No=“CIS19”
“An example of delete operation”
Update operation
• Update Operation: Changes the values of some attributes
of a tulpe
• update RELATION-NAME set attribute1=value1,
attribute2=value2, … where criteria
• update COURSES set Unit=6 where No=“CIS51”
“An example of update operation”
Select operation
• Select Operation: Uses some criteria to select some
tuples from the original relation
• select * from RELATION-NAME where criteria
• select * from COURSES where Unit=5
“An example of select operation”
Project operation
• Project Operation: Creates relation in which each tulpe
has fewer attributes
• select attribute-list from RELATION-NAME
• select No, Unit from COURSES
An example of a project operation
Join operation
• Join Operation: Takes two relation and combine them
based on common attribute
Union operation
• Union Operation: Creates new relation in which each
tuple is either in the first relation, the second relation or
in both
Intersection operation
• Intersection Operation: Creates new relation in
which each tuple is either in both relations.
Difference operation
• Difference Operation: Creates new relation where the
new tuples are in the first relation but not in the
second.
Microsoft Access Database
Basic Elements of Microsoft Access Database
Microsoft Access is a very easy and common software used to build
databases.
The first step to build a database is to determine the tables of the
database.
Microsoft Access provides the following elements for any database:
Tables
Relationships
Quires
Forms
Reports
Data Types of Table Fields
Microsoft Access provides several data types for the fields of database
tables, some examples of these types are:
Text
Number
Date/Time
Currency
Auto Number
OLE Object
Hyper Link
Look UP Wizard
Type of Database Relationships
Access provides two types of relationships (relations) between fields
of different tables for a database :
One-to-One relationship (1 –to- 1).
One-to-Many relationship (1 –to- ∞).
These relations depend on the relations between the mutual of
the related tables.
The term one of the relation types refers to that the field is
primary key in its table, while the term many refers to that the
field is not primary key.
EX1: Determine the relationships and its types between the
following fields:
EMPLOYEES
Employee_name ID Birth_date Gender Dept_code Job_grades
Record
SALARIES DEPARTMENTS
ID Salary Dept_code Dept_name
EMPLOYEES
Employee_name ID Birth_date Gender Dept_code Job_grades
Record
One-to-One relationship
1 ∞
One-to-Many relationship
1 SALARIES 1 DEPARTMENTS
ID Salary Dept_code Dept_name
EX2: Determine the relationships and its types between the
following fields:
DEPARTMENTS PROFESSORS
Dept_Code Dept_Name Prof_ID Prof_Name Dept_Code Course_No
COURSES STUDENTS
Course_No Course_Name Stud_ID Stud_Name Course_No
Solution
DEPARTMENTS PROFESSORS
Dept_Code Dept_Name Prof_ID Prof_Name Dept_Code Course_No
1 one-to-many relationship ∞ ∞
one-to-many relationship
1 COURSES STUDENTS
Course_No Course_Name Stud_ID Stud_Name Course_No
1 ∞
End