Professional Documents
Culture Documents
National University of Modern Languages - NUML: (Department of Computer Science)
National University of Modern Languages - NUML: (Department of Computer Science)
Languages - NUML
(Department of Computer Science)
Honors:
Magna Cumm Laude Honors Degree
Gold Medalist!
3
Continued…
Case Study
4
Relational Data Structure
5
Relational Data Structure
6
Continued…
7
Rows or Record or Tuples or Instances of an
ENTITY
A record contains all the information about a single ‘member’
of a table.
8
Relation (Table)
A relation is a named, two-dimensional table of data. A Table
consists of rows (tuples or records) and columns (attributes or fields)
10
Continued…
In A Relation.. Why?
11
Continued…
Correspondence with E-R Model
Relations/File (Tables) relates with ENTITY types in ERD
12
Continued…
Key Fields
Keys are special fields that serve two main purposes:
Primary Key
Foreign Key
(implements 1:N relationship
between customer and order)
14
15
Constraints
16
Constraints/Limitations/Check/Restrictions
These are used to limit the type of data that can go into a table.
This ensures the accuracy and reliability of the data in the database.
17
Type of Constraints
NOT NULL Constraint: Ensures that a column cannot have NULL value.
CHECK Constraint: The CHECK constraint ensures that all values in a column
satisfy certain conditions.
18
Integrity Constraints
19
Integrity
Types Constraints
of Integrity Constraints:
1) Domain Constraints:
2) Entity Integrity:
No primary key attribute have null value. All primary key fields must contain
Unique data.
20
Continued…
21
Domain definition Enforces Domain Integrity Constraints
Continued…
3) Referential Integrity:
This rule states that any foreign key value (on the
relation/table of the many side) MUST match a primary key value in the
relation/table of the one side in one_to_many type of relationship.
(Foreign key may store a null value but not Primary key)
For example: Update/Delete/Restrict Rules
Restrict: don’t allow update or delete of parent side records
(P.K) if related records that exists in dependent side/child table
(F.K)
Cascade: automatically update or delete dependent side/child
table records (F.K) that relates with the parent side records (P.K)
Set-to-Null: the foreign key (F.K) in the dependent side set to
null if deleting from the parent side (P.K).
Example:
EMPLOYEE to PARKING_PLACE (one_to_one type of relationship in
slide no. 52) 22
23
24
SQL table definitions
Referential
integrity
constraints are
implemented with
foreign key to
primary key
references
25
26
27
Well Structured Relation
28
Well Structured Relation
29
1. Insertion Anomaly/Irregularity/Inconsistency : Suppose that
we need to add a new employee to the table shown in next
slide. The primary key for this relation is the combination of
Emp_ID and Course_Title. Therefore, to insert a new record,
the user must supply values for both Emp_ID and Course_Title
(because primary key values cannot be null or nonexistent).
This is an anomaly. because the user should not be able to
enter only employee data without supplying course data.
30
Example of an Insertion, Deletion & Modification
Anomaly/Irregularity/Inconsistency
31
Solution to Remove Anomalies in a Relation via Database Design Phase :-
EMPLOYEE_to_COURSE :-
An EMPLOYEE must studies at least/more than
one COURSE’s. A COURSE must be studied by exactly one EMPLOYEE.
(ONE_to_MANY type of Relationship)
EMPLOYEE_to_DEPARTMENT :-
An EMPLOYEE must do his/her job in at most one
DEPARTMENT. In a DEPARTMENT at most one EMPLOYEE must do his/her
job (ONE_to_ONE type of Relationship)
Important Note:
All the Relationships are made as per given/provided
Record/Instance/Tuples in a Relation on slide no. 31
32
EMPLOYEE_to_COURSE :-
An EMPLOYEE must studies at least/more than
one COURSE’s. A COURSE must be studied by exactly one EMPLOYEE.
(ONE_to_MANY type of Relationship)
33
Transformation/Mapping of One_to_Many type of Relationship
from Conceptual Data Model into Logical Data Model:
34
EMPLOYEE_to_DEPARTMENT :-
An EMPLOYEE must do his/her job in at most one
DEPARTMENT. In a DEPARTMENT at most one EMPLOYEE must do his/her
job (ONE_to_ONE type of Relationship)
35
Transformation/Mapping of One_to_One type of Relationship
from Conceptual Data Model into Logical Data Model:
36
37
Transforming/Mapping ENTITIES into
Relations (Tables)
38
Transforming/Mapping ENTITIES into Relations
(Tables)
39
Continued…
(a) CUSTOMER
entity type with
simple attributes
40
Continued…
41
42
Continued…
43
Removing Multivalued Attributes from Tables
44
Continued…
(a)
49
Transforming/Mapping Weak ENTITIES
into Relation (Tables)
50
Mapping Weak Entities into Relation
(Tables)
51
Continued…
52
Continued…
Foreign key
54
Transforming/Mapping Unary
Relationship into Relations (Tables)
55
Transforming/Mapping Unary Relationship into
Relations (Tables)
Many-to-Many–Two relations:
One for the entity type
two attributes, both taken from the primary key of the entity
56
Continued…
(b) EMPLOYEE
relation with
recursive foreign
key
57
58
Continued…
(a) Bill-of-materials
relationships (M:N)
59
Transforming/Mapping Binary Relationship into
Relations (Tables)
60
Transforming/Mapping Binary Relationship into
Relations (Tables)
One-to-Many:
Primary key on the one side becomes a foreign key on
the many side
Many-to-Many:
Create a new relation named as Associative/Junction
Table with the primary keys of the two entities as its primary
key in Binary Degree of Relationship
One-to-One:
Primary key on the Strong/Independent side becomes a
foreign key on the Weak/Dependent side
61
Continued…
62
Continued…
Example of mapping an M:N relationship
a) Completes relationship (M:N)
64
Strong and Weak Entity Type Symbol of
Representation
65
Continued…
66
Continued…
67
Transforming/Mapping Ternary Relationship
into Relations (Tables)
68
Transforming/Mapping Ternary Relationship into
Relations (Tables)
69
Continued…
70
Continued…
Surrogate Key:
A Surrogate Key is any column or set of
columns that can be declared as the primary key instead of more
than two composite Primary keys that jointly makes a Cumbersome
key (CUMBERSOME meaning: Large Set).
73
Case Study
CINEMA
THEATER
SHOW_TIME
MOVIE
75
Relationships as per Business Rule
Each CINEMA must contain one or more THEATER and each
THEATER must belong to only and only one CINEMA.
76
Reasoning for Type of Relationships: -
77
Reasoning behind finding Type of Relationships with a Associative/Junction Table: -
cinemaPhoneNumber is a Multi-Valued attribute, so it must be transformed into new ENTITY
Always check on instances of entity type; If the instance is
redundant/repeated in relational database in any of the two related
tables than it is not in a Well Structured Relation as per definition of
a Well Structured Relation.
81
Lab Activity 2 – SQL Syntax, Keywords,
DDL Commands
82
Lab Activity 2 – SQL Syntax, Keywords, DDL Commands
83
Transformation/Mapping of Database Design
Phase (ERD) of Lab 1 into Relations
84
Transformation/Mapping of Database Design Phase
(ERD) of Lab 1 into Relations
85
Recommended Readings
Chapter 5 from:
86
Summary of Lecture
➦ Lecture 5
87
Summary of Lecture (Continued…)
➦ Lecture 5
Case Study
89