Professional Documents
Culture Documents
Ver.
Ver. 1.0
1.0 Slide
Slide11of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Objectives
Ver.
Ver. 1.0
1.0 Slide
Slide22of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Database Management System
Ver.
Ver. 1.0
1.0 Slide
Slide33of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Data Models
Ver.
Ver. 1.0
1.0 Slide
Slide44of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Object-Based Logical Model
The ER model:
Views the real world as a collection of objects or entities and
the relationship among them.
An entity:
Is any object, place, person, or activity about which the data is
recorded.
Can be categorized as entity type and entity instance.
An entity can be of the following types:
Dependent entity
Independent entity
Ver.
Ver. 1.0
1.0 Slide
Slide55of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Object-Based Logical Model (Contd.)
A relationship is:
Defined as an association among entities.
Depicted in a diamond shaped box with the name of the
relationship type inside it.
The following diagram depicts a relationship between the
entities (TEACHER and STUDENT).
Relationship
Ver.
Ver. 1.0
1.0 Slide
Slide66of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Just a minute
Ver.
Ver. 1.0
1.0 Slide
Slide77of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Just a minute (Contd.)
Solution:
Entities: SUPPLIER and PARTS
Relationship: SHIPS
Ver.
Ver. 1.0
1.0 Slide
Slide88of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Object-Based Logical Model (Contd.)
Ver.
Ver. 1.0
1.0 Slide
Slide99of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Just a minute
Solution:
ellipses
Ver.
Ver. 1.0
1.0 Slide
Slide10
10of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Just a minute
Ver.
Ver. 1.0
1.0 Slide
Slide11
11of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Object-Based Logical Model (Contd.)
A subtype:
Is a subset of another entity.
Is always dependent on the supertype for its existence.
The attributes of a supertype apply to all of its subtypes.
The following diagram depicts the relationship between
supertype (COURSE) and subtypes (STANDLONE and
SEMESTER).
Ver.
Ver. 1.0
1.0 Slide
Slide12
12of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Just a minute
Ver.
Ver. 1.0
1.0 Slide
Slide13
13of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Just a minute (Contd.)
Solution:
Subtypes: Cash and Credit
Supertype: Suppliers
Ver.
Ver. 1.0
1.0 Slide
Slide14
14of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Record-Based Logical Model
Ver.
Ver. 1.0
1.0 Slide
Slide15
15of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Record-Based Logical Model (Contd.)
Ver.
Ver. 1.0
1.0 Slide
Slide16
16of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Steps for Creating an ER Diagram
Ver.
Ver. 1.0
1.0 Slide
Slide17
17of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Just a minute
Solution:
ER model
Ver.
Ver. 1.0
1.0 Slide
Slide18
18of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Steps for Creating an ER Diagram (Contd.)
Constructing an
ER Diagram
Ver.
Ver. 1.0
1.0 Slide
Slide19
19of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Relational Operators
Ver.
Ver. 1.0
1.0 Slide
Slide20
20of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Relational Operators (Contd.)
Relational Algebra
Ver.
Ver. 1.0
1.0 Slide
Slide21
21of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
RESTRICT
Extracted Rows
Ver.
Ver. 1.0
1.0 Slide
Slide22
22of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
PROJECT
Extracted Columns
Ver.
Ver. 1.0
1.0 Slide
Slide23
23of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
PRODUCT
The product operator joins two relations such that every tuple of
the first relation is matched with every tuple of the second relation.
To be product compatible, the two tables must have common
attributes.
The following diagram shows an example of the product operator.
Ver.
Ver. 1.0
1.0 Slide
Slide24
24of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
UNION
Ver.
Ver. 1.0
1.0 Slide
Slide25
25of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
INTERSECT
Ver.
Ver. 1.0
1.0 Slide
Slide26
26of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
DIFFERENCE
Ver.
Ver. 1.0
1.0 Slide
Slide27
27of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
JOIN
Ver.
Ver. 1.0
1.0 Slide
Slide28
28of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
DIVIDE
Ver.
Ver. 1.0
1.0 Slide
Slide29
29of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Just a minute
Solution:
Restrict
Ver.
Ver. 1.0
1.0 Slide
Slide30
30of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Conceptual Model
Ver.
Ver. 1.0
1.0 Slide
Slide31
31of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Mapping ER Diagrams to Tables
Ver.
Ver. 1.0
1.0 Slide
Slide32
32of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Mapping ER Diagrams to Tables (Contd.)
Regular entities:
They can exist alone, independent of any other entity.
They are the “building blocks” of the database.
Each regular entity maps to a table.
For example, STUDENT and BOOKS are two separate entities
in the following ER diagram.
Ver.
Ver. 1.0
1.0 Slide
Slide33
33of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Mapping ER Diagrams to Tables (Contd.)
Attributes:
Each property or attribute shown in the ER diagram maps to an attribute in the
appropriate table.
In the following ER diagram, STUDENT and BOOKS individually have different
attributes.
Ver.
Ver. 1.0
1.0 Slide
Slide34
34of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Mapping ER Diagrams to Tables (Contd.)
Relationships:
Map to tables in a different manner in the relational DBMS,
which depends on the type of the relationship.
Click the following link to view an animation on mapping
an ER diagram to table.
RDBMS_02_Relationship.swf
Ver.
Ver. 1.0
1.0 Slide
Slide35
35of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Mapping ER Diagrams to Tables (Contd.)
Weak entity:
It is an entity whose existence depends on some other entity.
The following diagram depicts the weak entity (EMPLOYEEADDRESS).
The EMPLOYEEADDRESS
entity can be mapped to a
separate table.
Ver.
Ver. 1.0
1.0 Slide
Slide36
36of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Mapping ER Diagrams to Tables (Contd.)
Ver.
Ver. 1.0
1.0 Slide
Slide37
37of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Tips on Logical Database Design
Ver.
Ver. 1.0
1.0 Slide
Slide38
38of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Attributes
Ver.
Ver. 1.0
1.0 Slide
Slide39
39of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Keys
RDBMS_02_Keys.swf
Ver.
Ver. 1.0
1.0 Slide
Slide40
40of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Just a minute
Solution:
Alternate
Ver.
Ver. 1.0
1.0 Slide
Slide41
41of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Just a minute
Solution:
Composite
Ver.
Ver. 1.0
1.0 Slide
Slide42
42of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Entities
Attribute
ADDRESS
becomes an
entity.
Ver.
Ver. 1.0
1.0 Slide
Slide43
43of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Subentities
Ver.
Ver. 1.0
1.0 Slide
Slide44
44of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Demo: Mapping the ER Diagram to Tables
Problem Statement:
Map the following ER diagram to its corresponding tables.
Ver.
Ver. 1.0
1.0 Slide
Slide45
45of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Summary
Ver.
Ver. 1.0
1.0 Slide
Slide46
46of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
Summary (Contd.)
Ver.
Ver. 1.0
1.0 Slide
Slide47
47of
of68
48
Querying Data
Introduction toUsing SQL Database
Relational Server Management Systems
What’s Next?
Ver.
Ver. 1.0
1.0 Slide
Slide48
48of
of68
48