WXGE 6101 DATABASE CONCEPTS & IMPLEMENTATIONS. Lesson Overview The Relational Model Terminology of relational model. Properties of database relations.

Slides:



Advertisements
Similar presentations
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Advertisements

The Entity-Relationship Model
Copyright © 2015 Pearson Education, Inc. Database Design Chapters 17 and
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Systems Development Life Cycle
© 2005 by Prentice Hall 1 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 7 th Edition Jeffrey A. Hoffer, Mary B.
© 2005 by Prentice Hall Chapter 3a Database Design Modern Systems Analysis and Design Fourth Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
1 Minggu 2, Pertemuan 3 The Relational Model Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Database Architecture The Relational Database Model.
Normalization Rules for Database Tables Northern Arizona University College of Business Administration.
Concepts of Database Management, Fifth Edition
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
© Pearson Education Limited, Chapter 2 The Relational Model Transparencies.
Module Title? DBMS E-R Model to Relational Model.
Relational Model Session 6 Course Name: Database System Year : 2012.
Chapter 4 The Relational Model.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
Week 6 Lecture Normalization
Web-Enabled Decision Support Systems
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
Concepts and Terminology Introduction to Database.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
CS 3630 Database Design and Implementation. 2 Mathematical Relation A mathematical relation is a subset of a Cartesian Product. A1  A2  A3  …  An.
Page 1 Topic 4 Relational Databases CPS510 Database Systems Abdolreza Abhari School of Computer Science Ryerson University.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Chapter 3 The Relational Model. 2 Chapter 3 - Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall, Modified by Dr. Mathis 3-1 David M. Kroenke’s Chapter Three: The Relational.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
1 Mathematical Relation A mathematical relation is a subset of a Cartesian Product. A1  A2  A3  …  An = {(x1, x2, x3, …, xn): xi  Ai} R  A1  A2.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
Relational Database. Database Management System (DBMS)
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
CIS 210 Systems Analysis and Development Week 6 Part II Designing Databases,
Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida Relationships—Topics.
Dr Gordon Russell, Napier University Data Analysis 3 - V2.0 1 Data Analysis 3 Unit 2.3.
Data Analysis 3 Chapter 2.3 V3.0 Napier University Dr Gordon Russell.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
The Relational Model. 2 Relational Model Terminology u A relation is a table with columns and rows. –Only applies to logical structure of the database,
Logical Database Design and the Relational Model.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
Ch 7: Normalization-Part 1
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
CS 3630 Database Design and Implementation. 2 Mathematical Relation A mathematical relation is a subset of a Cartesian Product. A1  A2  A3  …  An.
Lecture 4: Logical Database Design and the Relational Model 1.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
NormalisationNormalisation Normalization is the technique of organizing data elements into records. Normalization is the technique of organizing data elements.
Microsoft Access CS 110 Fall Entity Relationship Model Entities Entities Principal data object about which information is to be collectedPrincipal.
Chapter 4 The Relational Model Pearson Education © 2009.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Rationale Databases are an integral part of an organization. Aspiring Database Developers should be able to efficiently design and implement databases.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
Logical Database Design and the Rational Model
Translation of ER-diagram into Relational Schema
© 2011 Pearson Education, Inc. Publishing as Prentice Hall
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Relational Database Design
Design tools and techniques for a relational database system
Chapter 4 The Relational Model Pearson Education © 2009.
Relationships—Topics
Presentation transcript:

WXGE 6101 DATABASE CONCEPTS & IMPLEMENTATIONS

Lesson Overview The Relational Model Terminology of relational model. Properties of database relations. Examples of Relations Transforming E-R Diagrams into the Relational Model  Representing 1:1 Relationship in the Relational Model  Representing 1: M Relationship in the Relational Model  Representing M: M Relationship in the Relational Model

The Relational Model A relation is represented by a two-dimensional table. The rows of the table (tuples) correspond to individual records and the columns correspond to attributes. The column contains values of a single attribute. The domain of attributes is the allowable values for that attribute.

Relational Data Model (cont…) The relational model is based on the mathematical notion of a relation. A relational model enables us to view data logically rather than physically. A relation is physically represented as a table. These tables are used to hold information about objects to be represented in the database.

Most popular data model Uses simple tables of columns and rows where the columns represent fields and rows represent records Application will have many linked tables 1 or more field can become a key field Key field is used to establish links to other tables Links allow you to access information contained in related tables Relational Data Model (cont…)

Relational Model Terminology A relation is a table with columns and rows.  Only applies to logical structure of the database, not the physical structure. Attribute is a named column of a relation. Domain is the set of allowable values for one or more attributes.

Alternative Terminology for Relational Model

Relational Model Terminology Tuple is a row of a relation. Relational Database is a collection of normalized relations with distinct relation names.

Properties of Relations Relation name is distinct from all other relation names in the relational schema. Each cell of relation contains exactly one atomic (single) value. Each attribute has a distinct name. Values of an attribute are all from the same domain.

Properties of Relations Each tuple is distinct; there are no duplicate tuples. Order of attributes has no significance. Order of tuples has no significance, theoretically.

Both entity sets and relationship sets are shown as tables. The STUDENT relation is represented by the STUDENT table. The Relational Model

The STUDENT table have columns for attributes STUID, STUNAME, MAJOR, and CREDITS. A column contains values of a single attribute. The STUID column contains only IDs of students. The domain of attributes is the allowable values for that attribute. The Relational Model

STUDENT Relation

The column names at the top of the table corresponds to the attributes of the relations. The values in the STUID column are all from the domain of STUID, other values are not permitted,e.g. student names will not be allowed. Columns can be interchanged if we know from the column names which attribute each column represents. STUDENT Relation

The table would remain the same if we place the CREDITS column before the MAJOR column. There can be no duplicate rows because each individual student is represented just once. The row S1005, Isa, History, 56 appears only once. STUDENT Relation

The conceptual schema can be represented by E-R diagrams. Objects which we would like to record are represented by entities. The association between entities are reprsented by relationships. Most of the relationship encountered in practical database mangement are of degree 2, i.e. they are binary. Transforming E-R diagrams into the Relational Model

In transforming entities into the relational model we begin by defining a relation for each entity. The name for the relation is the same as the name of the entity. The attributes of the relation is the attribute of the relation. Transforming E-R diagrams into the Relational Model

The STUDENT entity contains the following attributes: STUID, STUNAME, MAJOR, CREDITS, GRADE. To define this entity with a relation we define a relation for the entity and place the attributes in it as columns. If we know the attribute that identifies the entity, this attribute will become the key of the relation. Transforming E-R diagrams into the Relational Model

otherwise we must investigate the user requirements to determine what attribute or attributes can identify the entity. In the case of STUDENT entity STUID is the key. The keys are underlined in the following relation. Transforming E-R diagrams into the Relational Model

STUNAMESTUID GRADE STUDENT MAJOR CREDITS STUDENT ( STUDENT ( STUID,STUNAME, MAJOR, CREDITS, GRADE) Representation of an Entity with a Relation RELATION ENTITY

In a 1:1 relationship one enity type is associated with no more than one entity of another type. Suppose an employee is assigned exactly one company car and a car is assigned to exactly one employee. This relationship is thus 1:1. Representing 1:1 Relationships in the Relational Model

Representing a 1:1 relationship with the relational model is straightforward. Each entity is represented with a relation. The key of that relation is then placed in the other relation. Thus for the 1:1 relationship EMPLOYEE-Car, the key of EMPLOYEE is placed in CAR and the key of CAR is placed in EMPLOYEE. Representing 1:1 Relationships in the Relational Model

EMPLOYEE 1:1CAR 1.EMPLOYEE (EMPNO, EMPNAME, EMPADD,SALARY, REGNO) CAR (REGNO, SERIALNO,COLOR, MAKE, MODEL) 2.EMPLOYEE (EMPNO, EMPNAME, EMPADD,SALARY) CAR (REGNO, SERIALNO,COLOR, MAKE, MODEL, EMPNO) or Representing 1:1 Relationships in the Relational Model

EMPNO is a foreign key in in CAR and REGNO is a foreign key in EMPLOYEE. The key of either table can be placed in the other table. When the foreign key EMPNO is placed in CAR we can navigate from EMPLOYEE to CAR. Representing 1:1 Relationships in the Relational Model

Suppose we have an employee and we want to know the car that has been assigned to that employee. We use EMPNO to look up the the employee’s row in EMPLOYEE. From this row we obtain the REGNO of the car assigned to that employee. We then use this key to look up the car data in CAR. Representing 1:1 Relationships in the Relational Model

Suppose we want to know the employee that has been assigned to a particular car. To get the car data, we use REGNO to obtain the car’s row in CAR. From this row, we obtain the EMPNO of the employee that has been assigned this car. We then use this key to look up the employee data in EMPLOYEE. Representing 1:1 Relationships in the Relational Model

We can navigate from EMPLOYEE to CAR and CAR to EMPLOYEE using the appropriate design. To go from CAR to EMPLOYEE we look up the row in the CAR relation having the given REGNO. From this row we extract the the EMPNO and use this to access the employee data. Representing 1:1 Relationships in the Relational Model

To go from EMPLOYEE to CAR we look up the row of EMPLOYEE having the given EMPNO. From this row we extract the the REGNO and use this to access the car data. Although the two designs are equivalent in concept they may be different in performance. Representing 1:1 Relationships in the Relational Model

If a query in one direction is more common than a query in the other, we may prefer one design to the other. Representing 1:1 Relationships in the Relational Model

The second type of binary relationship is 1:M in which an entity of one type can be related to many entities of another type. This type of relationship is a parent child relationship. Representing 1:M Relationships in the Relational Model

Consider the relationship between DEPT and EMPLOYEE. This means that an employee can be attached with at most one department but a department can have more than one employees. Thus DEPT is the parent and EMPLOYEE is the child. Representing 1:M Relationships in the Relational Model

Representing 1:M relationships is also simple. First each entity is represented by a relation. Then the key of the relation representing the parent entity is placed in the relation representing the child entity. To represent the DEPT-EMPLOYEE relationship we place the key of DEPT, i.e. DNO in the EMPLOYEE relation. Representing 1:M Relationships in the Relational Model

1:M DEPTEMPLOYEE The 1:M Relationship of DEPT_EMPLOYEE DNO DNAME MGR ENO ENAME EADD DNO Data-Structure Diagram Showing the Relational Representation of DEPT-EMPLOYEE. Representing 1:M Relationships in the Relational Model

The relational scheme for the DEPT_EMPLOYEE relationship is : DEPT (DNO, DNAME, MGR) EMPLOYEE (ENO, ENAME, EADD, DNO ). We can process this relationship in both directions. Representing 1:M Relationships in the Relational Model

Given EMPNO we can look up the appropriate row in EMPLOYEE and get the DNO of the department from the row data. To get the rest of the DEPT data we use the DNO obtained from EMPLOYEE to look up the appropriate row in DEPT. To obtain all the employees name attached to a certain department we look up all rows in EMPLOYEE having the the department’s Representing 1:M Relationships in the Relational Model

DNO. The employee data is obtained from these rows. In a 1:1 relationship it does not matter in which relation we store the foreign key. In a 1:M relationship we store the key of the parent relation in the child relation. Suppose we try to put the child’s key in the parent relation. Representing 1:M Relationships in the Relational Model

Attributes can only have single values. The DEPT relation can only store the record of only one employee. The structure cannot be used to store the “many” side of the 1:M relationship. Thus, we place the key of the parent relation in the child relation. Representing 1:M Relationships in the Relational Model

Many-to-many relationship is a relationship where one entity type corresponds to many entities of the second type, and an entity of the second type corresponds to many entities of the first type. STUDENT-COURSE is an M:M relationship. Representing M:M Relationships in the Relational Model

A student can register for many courses and a course can be taken by many students. M:M relationships cannot be represented by relations in the same way that 1:1 and 1:M relationships are. First we define a relation for each of the entities; one relation for STUDENT and another relation for COURSE. Representing M:M Relationships in the Relational Model

We cannot put the key of COURSE (CNO)in the STUDENT relation because there are many courses and multiple values are not allowed in the cells of a relation. We have room only for one CNO so what do we do with the other courses that the student has registered for ? The same problem will occur if we try to put the key of STUDENT(SNO) in COURSE. Representing M:M Relationships in the Relational Model

We can readily store the key of the first course for which the student is registered. We have no place to store the identifier of the second and subsequent courses. The following table shows an incorrect representation of a M:M relationship. Representing M:M Relationships in the Relational Model

STUDENT Relation

COURSE Relation

In the table we have stored a row in the COURSE for each STUDENT registered for each course. So there are two records for COURSE 10 and two records for COURSE 30. We have duplicated the Course data and create modification anomalies. If we change the Course 10’s schedule we will have to change all the rows involved. (Modification Anomaly) Representing M:M Relationships in the Relational Model

How can we schedule a course until a student has registered for it ? (Insertion Anomaly) What happens if Student S1015 drops out of course 20 ? (Deletion Anomaly) The solution to this is to create a third relation that represents the relationship itself. This relation will store the correspondence of students to courses Representing M:M Relationships in the Relational Model

Such relations are called intersection relations. Each row of the relation documents the intersection of a particular student with a particular course. The data structure diagram for the following relationships is as follows: Representing M:M Relationships in the Relational Model

SNO SNAME MAJOR CREDITS CNO CNAME ROOM SNO CNO STUDENT COURSE Data Structure Diagram For STUDENT COURSE R’ship

The relationship from STUDENT to STUDENT- COURSE is 1:M. The relationship from COURSE to STUDENT- COURSE is also 1:M. The M:M relationship has been decomposed into two 1:M relationships. The key of STUDENT-COURSE is the combination of the keys of both its parents. STUDENT-COURSE Relationship

The key for an intersection relation is always the combination of parent keys. The relational scheme is as follows: STUDENT (SNO, SNAME, MAJOR, CREDITS). COURSE (CNO, CNAME, ROOM) STUDENT-COURSE (SNO, CNO) STUDENT-COURSE Relationship

A relation is represented by a two-dimensional table. The rows of the table (tuples) correspond to individual records and the columns correspond to attributes. The column contains values of a single attribute. The domain of attributes is the allowable values for that attribute. SUMMARY

Each cell of the table contains only one value. The values in a column all come from the same attribute. Each tuple is distinct there are no duplicate tuples The order of columns/rows(tuples) is immaterial. SUMMARY

Entities are transformed into the relational model by defining a relation for each entity. The name for the relation is the same as the name of the entity. The attributes of the relation is the attribute of the relation. The attribute that identifies the entity becomes the key of the relation( keys are underlined ). SUMMARY

In a 1:1 relationship each entity is represented with a relation. The key of that relation is then placed in the other relation. The key of one relation that is stored in a another relation is called a foreign key. We use this key to navigate from one relation to another. SUMMARY

In a 1:M relationships each entity is represented by a relation. Then the key of the relation representing the parent entity is placed in the relation representing the child entity. SUMMARY

M:M relationships cannot be represented by relations in the same way that 1:1 and 1:M relationships are. We define a relation for each of the entities; one relation for STUDENT and another relation for COURSE. Next we create a third relation that represents the relationship itself. SUMMARY

This relation will store the correspondence of students to courses The key of the intersection record is the combination of the keys of both its parents. SUMMARY