0% found this document useful (0 votes)
20 views61 pages

Fundamental of DB (Section 1-2-3)

Uploaded by

favifd765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views61 pages

Fundamental of DB (Section 1-2-3)

Uploaded by

favifd765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 61

Fundamen

tal
of
Databa
se
Agenda
KEY TOPICS DISCUSSED IN THIS PRESENTATION

• What is database(DB)

• Entity Relationship Diagram (ERD)

• Database Schema

• Examples and exercises


1
Part1
What is the different
between Data &
I nformation ?
DATA INFORMATION
DATA INFORMATION
we mean known The data that has
facts that can be
we mean known facts
been processed
recorded and that
that can be recorded The data that
have implicit
and that have implicit has been
meaning.
meaning. processed
What is database
(DB) ?
• A database is a
collection of related
data.
Bank DB Hospital Faculty
DB DB
Database Objects

DB
objects

Table Form Report Quer inde Vie


s s s y x w
Database Users

DB
Users

Database
Database
administrato End
designer
r users
What is
DBMS ?
Database Management
System. a computer
software application that
interacts with the user
Database
Users :
Actors on the Behind the
scene : scene :
Database Designer /
Administrator Implementor Tool
Database Designer Developers
End user Operators /
Software Maintenance
Engineering
Steps to
built
database
Step 1

• Define your target !!


For example: create database for
faculty organization
Step 2

• Database design using Entity Relationship


data model (ERD)
ERD diagrams

Graphical
representatio
n
Entity
Relations
hip
Diagram
(ERD)
Componen
ts of
ERD :
Entity &
Attribute
Entity
Examples :
Student Doctor Courses Department

Attribute
Examples :
Types of Entity

1-Strong entity
Every entity considered strong

2-Weak entity dependent

Entity based on another entity

emp dependent
Attributes
Types :

Simple: one part

Composite: divided into sub-parts


Attributes
Types :

• Single-value attribute: can have only a single


value

• Multivalued attributes: can have many


values
Attributes
Types :

Derived attribute: value may be calculated from other


attributes
Attributes
Types :
Relationship
s:
Note : Select verb to
represent relationship

• Degree f relationship
• Types of relatonship
• Participation
Relationship
s:

Rules of
relationship:

degree of relationship

• Unary
• Binary
Relationship
s:
Binary: Can have student
enroll
dept
more than one
relationship between
entities.
manager

Unary: Can have Employee works for


recursive relationships worker

and can indicate roles


for clarity.
Relationship
s:
Ternary:

Name
proj_name

Project Hires department


location
D_no

budget
end_date
start_date
phone
employee

name address

ID
Relationship
s:
Relationship
Types :

one to one
one to many
many to
many
Relationship Types
example :

1
emp
1 own car

1
emp
1
Manage Department
1
4
Relationship Types
example :

1 M
customer make order

M 1
account has branch

1
M work Department
emp
Relationship Types
example :

enroll M
Product M
order

Patient M enroll M
doctor
Participation of
Relationship
Entity
Relations
hip
Diagram
(ERD)
Example about scenario

There are many branches. Each branch has the following


attributes (branchno, address, fax_no, telno). There are
many employees. Each employee has the following
attributes (name, address, position, salary, gender,
empno). Name of an employee is structure that contains
two fields (last_name, first_name), address of employee
is also a structure that contains (no, street, city). In each
branch there are many employees working. Each
employee works for a single branch. Each branch is
managed by one and only one employee. And each
employee manages one and only one branch.
different types of Keys

• Candidate key (unique, Not Null)


• Primary key (pk)
• Foreign key (fk)
• Composite key
2 Database
Schema
The description of a
database
7 Steps to convert from
ERD to Schema :
1- Mapping of Regular Entity
Types . 2- Mapping of Weak
Entity Types .
3 Mapping of Binary 1 : 1
Relation Types .
4Mapping of Binary 1 : N Relationship
Types . 5- Mapping of Binary M : N
7 Steps to convert from ERD to
Schema :
1 2 3 4 5 6 7

S TE S TE S TE S TE S TE S TE S TE
P
Mapping P
Mapping P
Mapping P
Mapping P
Mapping P
Mapping P
Mapping
of of Weak of Binary of Binary of Binary of N-ary of Unary
Regular Entity 1:1 1:N M:N Relations Relations
Entity Types . Relation Relations Relations hip Types hip
Types . Types . hip Types hip Types
1- Mapping Regular
Entity :
a)Entity
Type with
Simple
attributes

b) Relation
Mapping Regular
Entity :
a)Entity Type
with
Composite
attributes.

b)Relation
Mapping Regular
Entity :
a) Entity Type
with
Multivalued
attributes

b)
Relation
Example with values

Emp_Id Skills

Emp_Id Name Address 10001 C++


10001 Farida Cairo 10001 C#
10001 python
10002 Lina Alex
10002 C#
10003 Hamza Aswan 10002 python
10004 Baraa Benisuef 10003 python
10005 Asmaa fayoum 10004 java
10005 C#
10005 python
2- Mapping Weak
Entity :

Relatio
n
3- Mapping 1 : 1 Relation
Types :
Put Primary key for partial participate
entity with another entity (total
participate ).

Any attribute in a relationship put it


with total participate entity.
An ER diagram for the COMPANY
database (1 : 1 Relation
Types)
An Relation (schema) for the
COMPANY database (1 : 1
Relation Types)
SSN Fname Lname Dno Dnumber Mgr-
10001 Farida mohamed SSN
10002 Lina mohamed 20 Human 10003
10003 Hamza mohamed resources
40 Sales 10004
10004 Baraa mohamed
50 Marketing 10001
10005 Asmaa mohamed 60 Accounting 10002
3- Mapping 1 : N Relation
Types :
Put Primary key for (1) entity with
another entity (many)
Put any attribute on the
relationship .
An ER diagram for the COMPANY
database (1 : N Relation
Types)
An Relation (schema) for the
COMPANY database (1 : N
Relation Types)
SSN Fname Lname Dnum Dno Dnumber
10001 Farida mohamed 40
20 Human
10002 Lina mohamed 60 resources
10003 Hamza mohamed 40 40 Sales
10004 Baraa mohamed 40 50 Marketing
10005 Asmaa mohamed 20 60 Accounting
10006 Aya mohamed
10007 Ahmed mohamed 50
10008 kareem mohamed 60
3- Mapping N : M Relation
Types :
Make a new relation contains the
primary keys from two entities .

Put any attribute on the


relationship .
An ER
diagram for
the
COMPANY
database
(N : M
Relation
Types)
An Relation (schema) for the
COMPANY database (N : M
Relation Types)
SSN Fname Lname Dnum Pno Pname location
10001 Farida mohamed 40
2223 project1
10002 Lina mohamed 60
2224 project2
10003 Hamza mohamed 40 2225 project3
10004 Baraa mohamed 40 2226 project4
10005 Asmaa mohamed 20

Essn Pno hours

10001 2224 32

10001 2225 34
10002 2223 35
10003 2224 36
An ER
diagram for
the
COMPANY
database.
An
Schem
a
diagra
m for
the
COMP
A NY
datab
as e.
3 Examples and
Exercises
An ER
diagram for
a BANK
database
Types of constraints

• NOT NULL Constraint: Ensures that a column cannot have NULL value.
• DEFAULT Constraint: Provides a default value for a column when none
is specified.
• UNIQUE Constraint: Ensures that all values in a column are different.
• PRIMARY Key: Uniquely identified each rows/records in a database
table.
• FOREIGN Key: Uniquely identified a row/record in any other database
table.
• CHECK Constraint: The CHECK constraint ensures that all values in a
column satisfy certain conditions.
• INDEX: Use to create and retrieve data from the database very quickly.

You might also like