Agenda  TMA01  M876 Block 2 Relational Theory. Data Modeling.

Slides:



Advertisements
Similar presentations
Chapter 2.1 V3.1 Napier University Dr Gordon Russell
Advertisements

Logical Database Design
The Relational Database Model
Data Modeling is an Analysis Activity
The Relational Model System Development Life Cycle Normalisation
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Chapter 6 Methodology Logical Database Design for the Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Database Design (Data Modeling) DCO11310 Database Systems and Design By Rose Chang.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
Chapter 4 ENTITY-RELATIONSHIP MODELLING.
Chapter 4 Entity-Relationship modeling Transparencies © Pearson Education Limited 1995, 2005.
LOGICAL DATABASE DESIGN
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Logical Database Design Nazife Dimililer. II - Logical Database Design Two stages –Building and validating local logical model –Building and validating.
The Relational Database Model
Entity-Relationship modeling Transparencies
1 Web-Enabled Decision Support Systems Entity-Relationship Modeling Prof. Name Position (123) University Name.
DeSiamorewww.desiamore.com/ifm1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall 7.1.
Databases Illuminated
CSC271 Database Systems Lecture # 6. Summary: Previous Lecture  Relational model terminology  Mathematical relations  Database relations  Properties.
Entity-relationship Modeling Transparencies 1. ©Pearson Education 2009 Objectives How to use ER modeling in database design. The basic concepts of an.
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
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.
Chapter 4 The Relational Model.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
Web-Enabled Decision Support Systems
Concepts and Terminology Introduction to Database.
Database Systems Lecture # 7 8 th Feb, Conceptual and Logical Design Person buys Product name pricenamessn Conceptual Model: Relational Model: (plus.
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj ER Model Lecture 1 © Akhilesh Bajaj, 2000, 2002, 2003, 2004.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
CSCI 3140 Module 3 – Logical Database Design for the Relational Model Theodore Chiasson Dalhousie University.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
1 Relational Databases and SQL. Learning Objectives Understand techniques to model complex accounting phenomena in an E-R diagram Develop E-R diagrams.
© Pearson Education Limited, Chapter 7 Entity-Relationship modeling Transparencies.
Chapter 12 Entity-Relationship Modeling Pearson Education © 2009.
DeSiamorePowered by DeSiaMore1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
Msigwaemhttp//:msigwaem.ueuo.com/1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
1 Chapter 17 Methodology - Local Logical Database Design.
Databases Illuminated Chapter 3 The Entity Relationship Model.
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
44220: Database Design & Implementation Review & Assignment 2 Ian Perry Room: C41C Tel Ext.: 7287
44220: Database Design & Implementation Implementing Physical Domains Ian Perry Room: C41C Tel Ext.: 7287
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,
Conceptual Design to Logical Design Lecture 4. Aims  To introduce Business Rules  To identify what a Business Rule is  To Introduce Business Operations.
Chapter 3: Modeling Data in the Organization. Business Rules Statements that define or constrain some aspect of the business Assert business structure.
Entity-Relationship Modeling. 2 Entity Type u Entity type –Group of objects with same properties, identified by enterprise as having an independent existence.
CSE 412/598 DATABASE MANAGEMENT COURSE NOTES 3. ENTITY-RELATIONSHIP CONCEPTUAL MODELING Department of Computer Science & Engineering Arizona State University.
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts - 6 th Edition Chapter 7: Entity-Relationship Model.
Mapping ER to Relational Model Each strong entity set becomes a table. Each weak entity set also becomes a table by adding primary key of owner entity.
CSCI 6315 Applied Database Systems Review for Midterm Exam I Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Methodology - Logical Database Design. 2 Step 2 Build and Validate Local Logical Data Model To build a local logical data model from a local conceptual.
Week 2 Lecture The Relational Database Model Samuel ConnSamuel Conn, Faculty Suggestions for using the Lecture Slides.
ENTITY RELATIONSHIP DIAGRAM. Objectives Define terms related to entity relationship modeling, including entity, entity instances, attribute, relationship.
Rationale Databases are an integral part of an organization. Aspiring Database Developers should be able to efficiently design and implement databases.
ENTITY-RELATIONSHIP MODELLING. Objectives: How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated with ER model.
COP Introduction to Database Structures
Logical Database Design and the Rational Model
Tables and Their Characteristics
Chapter -3- Data Modeling Using the Entity-Relationship Model
Entity-Relationship Modeling
CIS 207 The Relational Database Model
Lecture 2 The Relational Model
Chapter 3 The Relational Database Model
Review of Week 1 Database DBMS File systems vs. database systems
Database Dr. Roueida Mohammed.
Presentation transcript:

Agenda  TMA01  M876 Block 2 Relational Theory

Data Modeling

Entity-Relationship (E-R) Modelling  A conceptual data model is produced after data analysis stage.  It models data to be stored in database and their inter-relationships.  E-R modelling expresses data requirements in terms of entity types, attributes of entity types and relationships between entity types.  E-R diagram is a graphical representation of an E-R model.

Fundamental Constructs of E-R Model  An entity represents a thing that has meaning in a given context and about which there is a need to record data, e.g. student, staff, course, etc..  Entity type defines the properties common to a collection of entities.  An attributes is a component of an entity type that represent a single property of entities of that type.  A relationship is an association of entities that has meaning in a given context and which needs to be recorded.

Relationships  Involves one, two, or more entities, and documents an association between these entities.  Must have a name and occasionally, may carry data.  Three types of relationships: binary recursive ternary

Relationships  Binary  Recursive (Unary) Student Enrols Course Prerequisite

Degree of a Relationship  Used to document the number of occurrences of an entity that are associated with another entity.  One to One (1:1)  One to Many (1:N)  Many to Many (M:N)

Relational Terminlogy StudentIdNameRegisteredCounsellorNoRegion s01Akeroyd s02Thompson s05Ellis s07Gillies s09Reeves s10Urbach relation a tuple primary key degree (5) attributes cardinality (6) relation name Student

Example – Training Centre  The administrator of an IT training centre needs to maintain data on each member of staff working for the centre, on each student enrolling a course at the centre, and on the rooms used and equipment required for each session of practical activities. Staff working at the centre carry out a number of tasks, including organizing and teaching courses and managing other staff. Some staff may be enrolling as students, since the company encourages staff to enrol on its courses as part of its staff development programme. Each course taught at the centre has eight sessions of practical activities. For each item of equipment it necessary to record the room in which it is used.

Find Entity Types and Attributes  The administrator of an IT training centre needs to maintain data on each member of staff working for the centre, on each student enrolling a course at the centre, and on the rooms used and equipment required for each session of practical activities. Staff working at the centre carry out a number of tasks, including organising and teaching courses and managing other staff. Some staff may be enrolling as students, since the company encourages staff to enrol on its courses as part of its staff development programme. Each course taught at the centre has eight sessions of practical activities. For each item of equipment it necessary to record the room in which it is used.

Entity Types of Training Centre Staff Student Room CourseSession Equipment Entity types Staff(StaffNo, Name) Student(StudentId, Name) Course(CourseCode, Name) Session(CourseCode, SessionNo) Room(RoomNo, Capacity) Equipment(InventoryNo, Description)

Find Relationships Between Entity Types  The administrator of an IT training centre needs to maintain data on each member of staff working for the centre, on each student enrolling a course at the centre, and on the rooms used and equipment required for each session of practical activities. Staff working at the centre carry out a number of tasks, including organising and teaching courses and managing other staff. Some staff may be enrolling as students, since the company encourages staff to enrol on its courses as part of its staff development programme. Each course taught at the centre has eight sessions of practical activities. For each item of equipment it necessary to record the room in which it is used.

E-R Model of Training Centre Staff Student Teaches Room CourseSession Equipment Organises Manages Has Enrols Uses Requires LocatedIn MayBe Entity types Staff(StaffNo, Name) Student(StudentId, Name) Course(CourseCode, Name) Session(CourseCode, SessionNo) Room(RoomNo, Capacity) Equipment(InventoryNo, Description)

Relational Model  A relational model is based on three constructs: Relation Attribute Domain  A relation consists of a fixed set of attributes, each of which is defined on some underlying domain.  A domain is a named set of values.  Attribute(s) is candidate key if and only if it has the properties of uniqueness and minimality.  Primary key of a relation is one particular key chosen from the candidate keys.  The remaining candidate keys become alternate keys. Alternate key can have NULL value but NOT primary key.  Foreign key is attribute(s) in one relation, R 2, whose values are the same as values of a primary key of some relation, R 1 (where R 1 and R 2 are not necessarily distinct).

Translating an ER-Diagram into a Relational Model  Declare relations Identify primary keys.  Declare domain  Declare relationships Represent 1:N relationships using foreign keys. Represent 1:1 relationships using foreign keys and alternative keys. Represent M:N relationships using additional relations.  Declare constraints

Step 1 - Declare Relations relation Staff StaffNo : StaffIdentifiers Name : NamesOfPeople ManagerStaffNo : StaffIdentifiers CourseCode : CourseIdentifiers StudentId : StudentIdentifiers primary key StaffNo relation Student StudentId : StudentIdentifiers Name : NamesOfPeople CourseCode : CourseIdentifiers primary key StudentId relation Course CourseCode : CourseIdentifiers Name : NamesOfCourses OrganiserStaffNo : StaffIdentifiers primary key CourseCode relation Session CourseCode : CourseIdentifiers SessionNo : SessionIdentifiers primary key (CourseCode, SessionNo) relation Room RoomNo : RoomIdentifiers Capacity : RoomCapacity primary key RoomNo relation Equipment InventoryNo : EquipmentIdentifiers Description : DescriptionOfEquipment RoomNo : RoomIdentifiers primary key InventoryNo

Step 2 - Declare Domain model TrainingCentre domains CourseIdentifiers = c1..c9 DescriptionOfEquipment = string EquipmentIdentifiers = NamesOfCourses = string NamesOfPeople = string RoomIdentifiers = r01..r99 SessionIdentifiers = 1..8 StaffIdentifiers = StudentIdentifiers = RoomCapacity =

Step 3 – Declare 1:N Relationships Between Relations  Use primary key/foreign key mechanism.  Include the primary key of the relation on the 1: side of the relationship to the relation on the :N side.

1 (Mandatory) : N (Mandatory) Relationship Staff Student Teaches CourseSession Organises Manages Has Enrols MayBe relation Session CourseCode : CourseIdentifiers SessionNo : SessionIdentifiers primary key (CourseCode, SessionNo) {relationship Has} foreign key CourseCode references Course

1 (Mandatory) : N (Optional) Relationship Staff Student Teaches CourseSession Organises Manages Has Enrols MayBe relation Staff StaffNo : StaffIdentifiers Name : NamesOfPeople ManagerStaffNo : StaffIdentifiers CourseCode : CourseIdentifiers StudentId : StudentIdentifiers primary key StaffNo {relationship Teaches} foreign key CourseCode references Course allowed null

1 (Optional) : N (Mandatory) Relationship Staff Student Teaches CourseSession Organises Manages Has Enrols MayBe relation Course CourseCode : CourseIdentifiers Name : NamesOfCourses OrganiserStaffNo : StaffIdentifiers primary key CourseCode {relationship Organises} foreign key OrganiserStaffNo references Staff not allowed null

1 (Optional) : N (Optional) Relationship Staff Student Teaches CourseSession Organises Manages Has Enrols MayBe relation Staff StaffNo : StaffIdentifiers Name : NamesOfPeople ManagerStaffNo : StaffIdentifiers CourseCode : CourseIdentifiers StudentId : StudentIdentifiers primary key StaffNo {relationship Manages} foreign key ManagerStaffNo references Staff allowed null

Step 3 – Declare 1:1 Relationships Between Relations  Two steps involved Decide which one of the two relations will have the attribute declared as foreign key. Declare the foreign key to be an alternate key. Staff Student MayBe relation Staff StaffNo : StaffIdentifiers StudentId : StudentIdentifiers primary key StaffNo {relationship MayBe} alternate key StudentId foreign key StudentId references Student allowed null  

Step 3 – Declare M:N Relationships Between Relations  The primary key/foreign key mechanism CANNOT be used to represent a M:N relationship. (Why?).  Use an intersection relation to represent a M:N relationship. Its primary key consists of the combination of the primary keys of the two other relations.  In other words, the M:N relationship is decomposed into two 1:N relationships.

CourseCodeSessionNo c11 2 c21 2 RoomNoCapacity r140 r260 r3100 CourseCodeSessionNoRoomNoCapacity c11r140 c12r140 c21r260 c22r260 ??r3100 Include the primary key of the session relation to the primary key the room relation Why Primary Key/Foreign Key Mechanism CANNOT Be Used To Represent M:N Relationship? Session Room Primary key CANNOT be NULL!

Step 3 – Declare M:N Relationships Between Relations (Cont.) Session Uses Room Session RoomUse follow must be mandatory  For example, relation Use CourseCode : CourseIdentifiers SessionNo : SessionIdentifiers RoomNo : RoomIdentifiers primary key (CourseCode, SessionNo, RoomNo) foreign key (CourseCode, SessionNo) references Session foreign key RoomNo references Room

Revised E-R Diagram of Training Centre Staff Enrolment Teaches Room CourseSession Equipment Organises Manages Has LocatedIn MayBe Use Require Student

Relational Model of Training Centre - After Step 3 relation Staff StaffNo : StaffIdentifiers Name : NamesOfPeople ManagerStaffNo : StaffIdentifiers CourseCode : CourseIdentifiers StudentId : StudentIdentifiers primary key StaffNo {relationship Manages} foreign key ManagerStaffNo references Staff allowed null {relationship Teaches} foreign key CourseCode references Course allowed null {relationship MayBe} alternate key StudentId foreign key StudentId references Student allowed null

Relational Model of Training Centre - After Step 3 relation Student StudentId : StudentIdentifiers Name : NamesOfPeople primary key StudentId relation Course CourseCode : CourseIdentifiers Name : NamesOfCourses OrganiserStaffNo : StaffIdentifiers primary key CourseCode {relationship Organises} foreign key OrganiserStaffNo references Staff not allowed null relation Enrolment StudentId : StudentIdentifiers CourseCode : CourseIdentifiers primary key (StudentId, CourseCode) foreign key StudentId references Student foreign key CourseCode references Course

Relational Model of Training Centre - After Step 3 relation Session CourseCode : CourseIdentifiers SessionNo : SessionIdentifiers primary key (CourseCode, SessionNo) {relationship Has} foreign key CourseCode references Course relation Use CourseCode : CourseIdentifiers SessionNo : SessionIdentifiers RoomNo : RoomIdentifiers primary key (CourseCode, SessionNo, RoomNo) foreign key (CourseCode, SessionNo) references Session foreign key RoomNo references Room

Relational Model of Training Centre - After Step 3 relation Room RoomNo : RoomIdentifiers Capacity : RoomCapacity primary key RoomNo relation Requires CourseCode : CourseIdentifiers SessionNo : SessionIdentifiers InventoryNo : EquipmentIdentifiers primary key (CourseCode, SessionNo, InventoryNo) foreign key (CourseCode, SessionNo) references Session foreign key InventoryNo references Equipment relation Equipment InventoryNo : EquipmentIdentifiers Description : DescriptionOfEquipment RoomNo : RoomIdentifiers primary key InventoryNo {relationship LocatedIn} foreign key RoomNo references Room not allowed null

Step 4 – Declare Constraints  Key Constraints Primary keys Alternative keys Foreign keys and referential integrity  If a relation R 2 has a foreign key, F, that references the primary key, P, in another relation, R 1, then ever R 2.F entry must either be a value equal to an R 1.P primary key value or be null.  Attribute Constraints Allowing NULL Attribute conditions, e.g. constraint today – DOB > 18  General Constraints Mandatory participation conditions  :1 side - Use relational algebra  :n side - Use NOT NULL Inclusivity/exclusivity conditions

Relational Model of Training Centre model TrainingCentre domains CourseIdentifiers = c1..c9 DescriptionOfEquipment = string EquipmentIdentifiers = NamesOfCourses = string NamesOfPeople = string RoomIdentifiers = r01..r99 SessionIdentifiers = 1..8 StaffIdentifiers = StudentIdentifiers = RoomCapacity =

Relational Model of Training Centre relation Staff StaffNo : StaffIdentifiers Name : NamesOfPeople ManagerStaffNo : StaffIdentifiers CourseCode : CourseIdentifiers StudentId : StudentIdentifiers primary key StaffNo {relationship Manages} foreign key ManagerStaffNo references Staff allowed null {relationship Teaches} foreign key CourseCode references Course allowed null {relationship MayBe} alternate key StudentId foreign key StudentId references Student allowed null

Relational Model of Training Centre relation Course CourseCode : CourseIdentifiers Name : NamesOfCourses OrganiserStaffNo : StaffIdentifiers primary key CourseCode {relationship Organises} foreign key OrganiserStaffNo references Staff not allowed null constraint (project Course over CourseCode) difference (project Staff over CourseCode) is empty constraint (project Course over CourseCode) difference (project Session over CourseCode) is empty

Relational Model of Training Centre relation Student StudentId : StudentIdentifiers Name : NamesOfPeople CourseCode : CourseIdentifiers primary key StudentId {relationship Attends} foreign key CourseCode references Course not allowed null constraint (project Student over StudentId) difference (project Enrolment over StudentId) is empty relation Enrolment StudentId : StudentIdentifiers CourseCode : CourseIdentifiers primary key (StudentId, CourseCode) foreign key StudentId references Student foreign key CourseCode references Course

Relational Model of Training Centre relation Session CourseCode : CourseIdentifiers SessionNo : SessionIdentifiers primary key (CourseCode, SessionNo) {relationship Has} foreign key CourseCode references Course constraint (project Session over CourseCode, SessionNo) difference (project Use over CourseCode, SessionNo) is empty relation Use CourseCode : CourseIdentifiers SessionNo : SessionIdentifiers RoomNo : RoomIdentifiers primary key (CourseCode, SessionNo, RoomNo) foreign key (CourseCode, SessionNo) references Session foreign key RoomNo references Room

Relational Model of Training Centre relation Room RoomNo : RoomIdentifiers Capacity : RoomCapacity primary key RoomNo relation Requires CourseCode : CourseIdentifiers SessionNo : SessionIdentifiers InventoryNo : EquipmentIdentifiers primary key (CourseCode, SessionNo, InventoryNo) foreign key (CourseCode, SessionNo) references Session foreign key InventoryNo references Equipment relation Equipment InventoryNo : EquipmentIdentifiers Description : DescriptionOfEquipment RoomNo : RoomIdentifiers primary key InventoryNo {relationship LocatedIn} foreign key RoomNo references Room not allowed null

Manipulating Relations

Select Operator  The general form of a select expression is:-  select where  Produce a relation whose extension is a subset of the extension of a given relation, the content of the subset being determined by a selection condition.  Can be though of ‘slicing’ a relation horizontally.  For example,  select Student where Registered > 1996

Project Operator  The general form of a project expression is:-  project over  Pick out the wanted attributes from a given relation.  Can be though of ‘slicing’ a relation vertically.  For example,  project Course over Title, Credit

Join Operator  The general form of a join expression is :-  join and where =  'Paste' tuples of two relations together where the condition in the join expression holds.  Attributes in a condition must be defined on same domain.  The possible duplication of attribute names is a minor problem as the result of a join (can be resolved by qualified attribute names).  E.g. join Student and Staff where CounsellorNo = StaffNo

Divide Operator  The general form of a divide expression is :-  divide by over  Reduce a relation into a smaller relation, which contain only those tuples for which the second relation was a 'factor'.  E.g. divide Studies by AllCourses over CourseCode Studies AllCourses

Union Operator  The general form of a union expression is :-  union  and must be union- compatible.  Two relations are union-compatible only if They are of the same degree There is a one-to-one mapping between each attribute Corresponding attributes are defined on the same domain  The result of a union is a relation containing all the tuples belonging to either or (or to both).  E.g. Region4Students union CourseCodec4Students

Union Operator Region4Students CourseCodec4Students

Venn Diagram

Intersection Operator  The general form of a intersection expression is :-  intersection  The result of a intersection is a relation containing all the tuples belonging to both and.  E.g. Region4Students intersection CourseCodec4Students

Intersection Operator Region4Students CourseCodec4Students

Venn Diagram

Difference Operator  The general form of a difference expression is :-  difference  The result of a difference is a relation containing the tuples that belong to but do not belong to.  E.g. Region4Students difference CourseCodec4Students

Difference Operator Region4Students CourseCodec4Students

Venn Diagram

Example 1  Produce a relation containing the identifiers of rooms that are not used for any of the practical sessions. 1.project Room over RoomNo giving AllRooms 2.project Uses over RoomNo giving RoomsUsed 3.AllRooms difference RoomsUsed giving Answer OR (project Room over RoomNo) difference (project Uses over RoomNo) giving Answer

Example 2  Produce a relation containing the identifiers of rooms that are used for at least one practical session and can accommodate at least ten students. 1.join Uses and Room where Uses.RoomNo = Room.RoomNo giving RoomsUsed 2.select RoomsUsed where Capacity >= 10 giving LargeRoomsUsed 3.project LargeRoomsUsed over RoomNo giving Answer OR ‏project ( select ( join Uses and Room where Uses.RoomNo = Room.RoomNo) where Capacity >= 10) over RoomNo giving Answer

Example 3  Staff attending a course at the centre as students must not be involved in the organization or teaching of that course. Write a query that check this rule and give empty relation if it has not been broken. 1.join Staff and Student where Staff.StudentId = Student.StudentId giving StaffAsStudents 2.project StaffAsStudents over StaffNo, Student.CourseCode giving Students 3.project Staff over StaffNo, CourseCode giving Teachers 4.project Course over OrganizerStaffNo, CourseCode giving CourseManagers 5.Teachers union CourseManagers giving Teachers&CourseManagers 6.Students interaction Teachers&CourseManagers giving Answer