35
DATABASE CONCEPTS & ER MODEL Instructor: 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 1

DATABASE CONCEPTS & ER MODEL

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: DATABASE CONCEPTS & ER MODEL

DATABASE CONCEPTS &

ER MODEL

Instructor:

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 1

Page 2: DATABASE CONCEPTS & ER MODEL

Learning Goals

2

By the end of this lecture students

should be able to:

Understand an overview of the basic RDBMSConcepts

Understand an insight into the architecture andcomponents of a Database System.

Describe how entities, attributes and relationshipsare used to model data;

Converting ER Model to relational schema

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 3: DATABASE CONCEPTS & ER MODEL

Table of contents

◊ SQL Overview SQL Overview

◊ The Relational Database

◊ RDBMS Concepts

◊ ER Model

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 3

Page 4: DATABASE CONCEPTS & ER MODEL

SQL OVERVIEWSection 1

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 4

Page 5: DATABASE CONCEPTS & ER MODEL

5

What is SQL?

Structured

Query

Language

Which is a computer language for:

storing,

manipulating and

retrieving data stored in relational database.

SQL is the standard language for Relation Database System, like MySQL, MS

Access, Oracle, Sybase, Informix, Postgres and SQL Server use SQL as

standard database language.

SQL is an ANSI (American National Standards Institute) standard.

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 6: DATABASE CONCEPTS & ER MODEL

SQL Process

6

SQL QueryQuery Language

Processor

DBMS Engine

Physical Database

Parser + Opimizer

File Manager+

Transaction manager

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 7: DATABASE CONCEPTS & ER MODEL

SQL Commands

SQL consists of three components:

Data Definition Language (DDL)

Data Manipulation Language (DML) and

Data Control Language (DCL)

709e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 8: DATABASE CONCEPTS & ER MODEL

THE RELATIONAL DATABASESection 2

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 8

Page 9: DATABASE CONCEPTS & ER MODEL

Relational Database Concepts (1/3)

“A DBMS that manages data as collection of tables in which all datarelationships are represented by common values in related tables.”

“A DBMS that follows all the twelve rules of CODD is called RDBMS”

909e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 10: DATABASE CONCEPTS & ER MODEL

10

Field

Record

Relational Database Concepts (2/3)

CD_ID Title Artist Genre

1 The Wall Pink Floyd Rock

2 Blue Train John Coltrane Jazz

3 Requiem W.A. Mozart Classical

Table

Page 11: DATABASE CONCEPTS & ER MODEL

11

Relational Database Concepts (3/3)

Field

Cardinality

Primary

Key

Row/

Record

DomainDomain

SCode SName Quantity City

S1 Kamran 20 Lahore

S2 Zafar 10 Islamabad

S3 Azmat 40 Karachi

S4 Abdul 34 Lahore

S5 Nasir 25 Islamabad

Supplier

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 12: DATABASE CONCEPTS & ER MODEL

Schema (1/2)

The name of a relation and the set of attributes for a relation is called a

schema.

– Example: the schema for previous slide is

Supplier (SCode, SName, Quantity, City)

Relation schema = name(attributes) + other structure info., e.g., keys,

other constraints.

Order of attributes is arbitrary, but in practice we need to assume the

(standard) order given in the relation schema.

Relational database schema = collection of relation schemas.

1209e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 13: DATABASE CONCEPTS & ER MODEL

Schema (2/2)

Relation schema example:

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 13

Page 14: DATABASE CONCEPTS & ER MODEL

Schema versus Instance

sid Name Login age GPA

53666 Jones Jones@ca 18 3.4

53444 smith Smith@ecs 18 3.2

53777 Blake Blake@aa 19 3.8

Cardinality = 3, arity = 5 , all rows distinct

Do all values in each column of a relation instance have to be distinct?

Student(studno,name,address)

Course(courseno,lecturer)

Student(123,Bloggs,Woolton)

(321,Jones,Owens)

Schema

Instance

1409e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 15: DATABASE CONCEPTS & ER MODEL

What is RDBMS?

RDBMS stands for:

Relational Database Management System

RDBMS is the basis for SQL, and for all modern database systems like:

MS SQL Server,

IBM DB2,

Oracle,

MySQL,

and Microsoft Access.

A Relational database management system (RDBMS) is a database

management system (DBMS) that is based on the relational model as

introduced by E. F. Codd.1509e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 16: DATABASE CONCEPTS & ER MODEL

DBMS RDBMS

The concepts of relationships is

missing in a DBMS. If it exits it is

very less.

It is based on the concept

Of relationships

Speed of operation is very slow Speed of operation is very Fast

Hardware and Software

requirements are minimumHardware and Software

requirements are High

Platform used is normally DOS Platform used can be any DOS,

UNIX,VAX,VMS, etc

Uses concept of a file Uses concept of table

DBMS normally use 3GL RDBMS normally use a 4GL

Examples are dBase, FOXBASE, etc Examples are ORACLE, INGRESS,

SQL Server 2000 etc

DBMS vs. RDBMS

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 16

Page 17: DATABASE CONCEPTS & ER MODEL

ER MODELSection 3

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 17

Page 18: DATABASE CONCEPTS & ER MODEL

Design Process

Requirement collection &

Analysis

Requirement database

Conceptual design

Conceptual model

Real world Survey

Interview Collect requirement Analisys

Modelling Design

Specification

ER Modelling

……..

1809e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 19: DATABASE CONCEPTS & ER MODEL

19

Basic E-R Notation

Entity symbols

Relationship symbols

Attribute symbols

A special entity that is also a relationship

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 20: DATABASE CONCEPTS & ER MODEL

20

ER Model Overview

Sample E-R Diagram

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 21: DATABASE CONCEPTS & ER MODEL

One – to – one:

One – to – many:

21

Cardinality of Relationships (1/2)

EMPLOYEE DEPARTMENT

DEPARTMENT EMPLOYEE

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 22: DATABASE CONCEPTS & ER MODEL

Many – to – many:

In which:

22

Cardinality of Relationships (2/2)

EMPLOYEE PROJECT

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 23: DATABASE CONCEPTS & ER MODEL

23

Binary relationships

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 24: DATABASE CONCEPTS & ER MODEL

Converting ER Model to relational schema

Rule 1 - Convert entity type with simple attributes

CUSTOMER relation

CUSTOMER entity type with simple attributes

2409e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 25: DATABASE CONCEPTS & ER MODEL

Multivalued attribute becomes a separate relation with foreign key

1–to–many relationship between original entity and new relation

Converting ER Model to relational schema

Rule 2 - Convert Multivalue attribute

2509e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 26: DATABASE CONCEPTS & ER MODEL

Converting ER Model to relational schema

Rule 3 - Convert Unary relationship one to one

EMPLOYEE relation with recursive foreign key

EMPLOYEE entity with Manages relationship

2609e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 27: DATABASE CONCEPTS & ER MODEL

Converting ER Model to relational schema

Rule 4 – Convert binary relationship one to one

2709e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 28: DATABASE CONCEPTS & ER MODEL

Converting ER Model to relational schema

Rule 5 – Convert Unary relationship one to many

EMPLOYEE relation with recursive foreign key

EMPLOYEE entity with Manages relationship

2809e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 29: DATABASE CONCEPTS & ER MODEL

Converting ER Model to relational schema

Rule 6 – Convert Binary relationship one to many

Note the mandatory one

Again, no null value in the foreign key…this is because of the mandatory minimum cardinality

2909e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 30: DATABASE CONCEPTS & ER MODEL

Converting ER Model to relational schema

Rule 7 – Convert Unary relationship many to many

Bill-of-materials relationships (M:N)

ITEM and COMPONENT relations

3009e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 31: DATABASE CONCEPTS & ER MODEL

Converting ER Model to relational schema

Rule 8 – Convert Binary relationship many to many

New intersection relation

Foreign key Foreign key

Composite primary key

The Supplies relationship will need tobecome a separate relation

3109e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 32: DATABASE CONCEPTS & ER MODEL

Converting ER Model to relational schema

Another - Convert Ternary relationship

3209e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 33: DATABASE CONCEPTS & ER MODEL

Converting ER Model to relational schema

Another- Convert Ternary relationship (2)

3309e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use

Page 34: DATABASE CONCEPTS & ER MODEL

Summary

SQL Overview• SQL, SQL Process, SQL Command

The Relational Database• Table, Field, Record, Schema

RDBMS Concepts• RDBMS, RDBMS vs DBMS

ER Model• Design Process, Notation, Converting ER Model to relational

schema

09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 34

Page 35: DATABASE CONCEPTS & ER MODEL

Thank you

3509e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy -

Internal Use35