The Relational Model May Aldoayan.

Slides:



Advertisements
Similar presentations
RELATIONAL DATABASES. Relational data Structure RELATION: Table with columns and rows ATTRIBUTE: Column of a relation DOMAIN: Set of allowable values.
Advertisements

Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College.
Chapter 3 CIS 458 Sungchul Hong
The Relational Model System Development Life Cycle Normalisation
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
1 Minggu 2, Pertemuan 3 The Relational Model Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
1 Pertemuan 04 MODEL RELASIONAL Matakuliah: >/ > Tahun: > Versi: >
Relational Database Management System A type of database in which records are stored in relational form is called relational database management system.
Database Architecture The Relational Database Model.
Chapter 3 Relational Model Chapter 4 in Textbook.
Lecture4: Informal guidelines for good relational design Mapping ERD to Relation Ref. Chapter3 Lecture4 1.
CSC271 Database Systems Lecture # 6. Summary: Previous Lecture  Relational model terminology  Mathematical relations  Database relations  Properties.
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.
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
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.
SQL Structured Query Language Programming Course.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
The Relational Model Pertemuan 03 Matakuliah: M0564 /Pengantar Sistem Basis Data Tahun : 2008.
Relational Database. Database Management System (DBMS)
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Mapping from conceptual model (EER-M)
Logical Design database design. Dr. Mohamed Osman Hegaz2 Conceptual Database Designing –Provides concepts that are close to the way many users perceive.
12/2/2015CPSC , CPSC , Lecture 41 Relational Model.
L8-2-S1 Misc Topics © M.E. Fayad SJSU -- CmpE Database Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of.
Chapter 17 Logical Database Design for the Relational Model Pearson Education © 2009.
ER/EER to Relational Data Model 1 Database Design.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences The Relational.
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,
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
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.
Chapter 4 The Relational Model Pearson Education © 2009.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Chapter 7 Relational Database Design by ER- and EERR-to-Relational Mapping Copyright © 2004 Pearson Education, Inc.
Chapter 4 Relational Algebra Chapter 4 in Textbook.
COP Introduction to Database Structures
Teacher Workshop Database Design Pearson Education © 2014.
Relational Algebra Lecture 2.
Chapter 4 Logical Database Design and the Relational Model
Chapter 4: Logical Database Design and the Relational Model
Chapter 5: Logical Database Design and the Relational Model
Logical Database Design for the Relational Model
Chapter Design Methodology Pearson Education © 2009.
Chapter -3- Data Modeling Using the Entity-Relationship Model
The Relational Database Model
Data Base System Lecture 6: Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Database Normalization
DATABASE SYSTEM.
Chapter 4+17 The Relational Model Pearson Education © 2014.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter Entity-Relationship Modeling & Enhanced Entity- Relationship Modeling.
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
The Relational Model Transparencies
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Design tools and techniques for a relational database system
Chapter Entity-Relationship Modeling & Enhanced Entity- Relationship Modeling.
Chapter 4 The Relational Model Pearson Education © 2009.
Mapping an ERD to a Relational Database
Views Base Relation View
Chapter 3 The Relational Model
Presentation transcript:

The Relational Model May Aldoayan

Simple uses the concept of a mathematical relation Oracle SQLServer and Acces the SQL query language, which is the standard for commercial relational DBMSs.

The relational model represents the database as a collection of relations. Informally, each relation resembles a table of values or, to some extent, a flat file of records May Aldoayan

Relational Data structure Attributes Branch Figure 3.1 postcode City Street branchNo SW1 AEH London 22 Deer Rd B005 AB2 3SU Aberdeen 16 Argyll St B007 G11 9QX Glasgow 163 Main St B003 BS99 1NZ Bristol 32 Manse Rd B004 NW10 6EU 56 Clover Dr B002 Relation Cardinality Degree Foreign Key Primary Key Staff branchNo Salary DOB Sex Position LName fName StaffNo B005 30000 1-Oct-45 M Manager White John SL21 B003 12000 10-Nov-60 F Assistant Beech Ann SG37 18000 24-Mar-58 Supervisor Ford David SG14 B007 9000 19-Feb-70 Howe Mary SA9 24000 3-Jun-40 Brand Susan SG5 13-Jun-63 Lee Julie SL41 Relation May Aldoayan

Relational Data structure Relation: A relation is a table with columns and rows. In the relational model, relations are used to hold information about the object to be represented in the database. Attribute: An attribute is a named column of a relation. Attribute can appear in any order and the relation will still be the same relation, and therefore convey the same meaning May Aldoayan

Relational Data structure Domain : A domain is the set of allowable values for one or more attributes. Domains may be distinct for each attribute, or two or more attributes may be defined on the same domain. Tuple: A tuple is a row of a relation. The elements of a relation are the rows or tuples in the table. May Aldoayan

Examples of Attribute Domains Pearson Education © 2009

Relational Data structure Degree: The degree of a relation is the number of attributes it contains. In figure 3.1, The Branch relation has four attributes or degree four. This means that each row of the table is a four-tuple, containing four values. A relation with only one attribute would have degree one and be called unary relation or one-tuple. A relation with two attribute is called binary, one with three attribute is called ternary May Aldoayan

Relational Data structure Cardinality: The cardinality of a relation is the number of tuples it contain. Relational database: A collection of normalized relation with distinct relation name . Database relations: Relation schema: A named relation defined by a set of attribute and domain name pairs. Relational database schema: A set of relation schema, each with a distinct name. If R1, R2, .., Rn are a set of relation schemas, then relational schema R is: R= {R1, R2, .., Rn} May Aldoayan

Alternative Terminology for Relational Model Pearson Education © 2009

Properties of relations The relation has a name that is distinct from all other relation names in the relational schema. Each cell of the relation contains exactly single value Each attribute has a distinct name The values of an attribute are all of the same domain Each tuple is distinct. There are no duplicate tuples The order of attributes has no significance the order of tuples has no significance; theoretically May Aldoayan

Relational Keys Primary Key: The candidate key that is selected to identify tuples uniquely within the relation. Foreign Key : is an attribute, or set of attributes, within one relation that matches the CK of some relation. Used to represent relationship between tuples of two relations. May Aldoayan

Integrity Constraints Null Represents value for an attribute that is currently unknown or not applicable for tuple. Deals with incomplete or exceptional data. Represents the absence of a value and is not the same as zero or spaces, which are values. Pearson Education © 2009

Relation Schema Student Dept GPA DOB LName FName StudentNo D001 4.03 15-1-1993 Alsaleh Maha 431671078 3.90 5-6-1992 AlAhmed Reem 430670028 D002 3.50 3-7-1993 AlQahtani Sara 431679802 4.50 10-10-1994 Alotaibi Suha 432784900 D003 4.89 12-3-1992 AlMutairi Lamea 430453772 STUDENT (StudentNo, Lname, Fname, DOB, GPA, Dept) Department Location Name Department DeptNo Build# 1 Computer Science D001 Build# 3 Business Administrator Doo2 Build # 6 Science D003 DEPARTMENT (DeptNo, Department Name, Location) May Aldoayan

1:1 Relationship  Relational Model Identify an entity type (S) (preferably total participator) Include the PK of the other entity (T) as a FK in S Add attributes that describes the relationship. EMPLOYEE(EmpNo, Lname, Fname, DOB) BRANCH(BrnNo, Name, EmpNo) LName FName Name EmpNo DOB BrnNo 1 1 manage EMPLOYEE BRANCH (0,1) (1,1) May Aldoayan

1:M Relationship  Relational Model Identify a participating entity type (S) on the m-side Include the PK of the other entity type (T) as a FK in S if S is at “M-side” of relationship type then include primary key of T in S Add attributes that describes the relationship STAFF (StaffNo, Lname, Fname, DOB) PropertForRent(ProertyNo, Address, StaffNo) LName FName Address PropertyNo StafNo Name DOB 1 M Oversees Staff ProperyForRent (0,*) (1,1) May Aldoayan

M:N Relationship  Relational Model Create a new relation R to represent the relationship Include the PK of participating entity types (T & S) as FK in R. The combination of the two FK will form the PK of R Add attributes that describes the relationship EMPLOYEE(StaffNo, Lname, Fname, DOB) Project(ProjNo, Name) Work-on(EmpNo, ProjNo , hours) LName Name ProjNo Fname hours EmpNo DOB M N Work-on Employee Peoject May Aldoayan

n-ary Relationship  Relational Model Create a new relation R to represent the relationship Include the PK of the participating entities as FK in R. The combination of all FK form the PK of R. Add attributes that describes the relationship BUSINESS(BizNo) LAWYER(LawNo) SUPPLIER(SupNo) contract(BizNo, SupNo, LawNo, StartDate, EndDate) StartD EndD SupNo BizNo contract BUSINESS SUPPLIER Lawyer LawNo May Aldoayan

Composite Attribute Relational Model Include its simple components in the relation EMPLOYEE(EmpNo, Fname, initial, Lname, DOB) initial FName LName name DOB emp_no EMPLOYEE May Aldoayan

Multi Valued Attribute Relational Model Suppose A is a relation that contains the multi valued attribute Create a relation R to represent the attribute Include the PK of A as FK in R The PK of R is the combination of the PK of A (FK) & the multivalued attribute EMPLOYEE(EmpNo, DOB) TELEPHONE(EmpNo, tel_no) DOB EmpNo Tel_no EMPLOYEE May Aldoayan

EER Relational Model Mandatory/NonDisjoint Suppose specialization with subclasses (S1, S2, .., Sm} & a superclass C Create a relation L to represent C with PK & attributes Include the unshared attributes for each subclass Si, 1 i  m Add discriminator to distinguish the type of each tuple May Aldoayan

EER Relational Model Mandatory/NonDisjoint EMPLOYEE(EmpNo, Fname, Lname, DOB,Salary,TypingSpeed,TGrade, EngType, Secretary Flag, Technician Flag, Engineer Flag) Salary EmpNo LName EMPLOYEE Fname DOB o Typing Speed EngType SECRETARY TECHNICIAN ENGINEER TGrade May Aldoayan

EER Relational Model Mandatory/Disjoint Suppose specialization with subclasses (S1, S2, .., Sm} & a superclass C. Create a relation Li, 1 i  m, to represent each combination of super/subclass May Aldoayan

EER Relational Model Mandatory/Disjoint SECRETARY(EmpNo, Fname, Lname, DOB, Salary,TypingSpeed) TECHNICIAN(EmpNo, Fname, Lname, DOB, Salary,Tgrade) ENGINEER(EmpNo, Fname, Lname, DOB, Salary, EngType) Salary EmpNo LName EMPLOYEE Fname DOB d Typing Speed EngType SECRETARY TECHNICIAN ENGINEER TGrade May Aldoayan

EER Relational Model Optional/NonDisjoint Suppose specialization with subclasses (S1, S2, .., Sm} & a superclass C Create a relation L to represent C with PK & attributes Create a relation Li to represent each subclass Si, 1 i  m May Aldoayan

EER Relational Model Optional/NonDisjoint EMPLOYEE(EmpNo, Fname, Lname, DOB, Salary) SUB-EMP(EmpNo, TypingSpeed,TGrade, EngType, Secretary Flag, Technician Flag, Engineer Flag) Salary EmpNo LName EMPLOYEE Fname DOB o Typing Speed EngType SECRETARY TECHNICIAN ENGINEER TGrade May Aldoayan

EER Relational Model Optional/Disjoint Suppose specialization with subclasses (S1, S2, .., Sm} & a superclass C Create a relation L1 to represent C with PK & attributes Create a relation L2 to represent all subclasses Si, 1 i  m Add discriminator to distinguish the type of each tuple May Aldoayan

EER Relational Model Optional/Disjoint EMPLOYEE(EmpNo, Fname, Lname, DOB, Salary) SECRETARY(EmpNo, TypingSpeed) TECHNICIAN(EmpNo, Tgrade) ENGINEER(EmoNo, EngType) Salary EmpNo LName EMPLOYEE Fname DOB d Typing Speed EngType SECRETARY TECHNICIAN ENGINEER TGrade May Aldoayan

E/R  Relational Model Relational Model E/R Model Relational Entity Type FK or relation 1:1 or 1:M Relationship Type Relation & 2 FK M:N Relationship Type Relation & n FK n-ary Relationship Type Attribute Simple attribute Simple component attribute Composite attribute Relation and FK Multivalued attribute Domain Value set PK Key attribute May Aldoayan

Integrity Constraints General Constraints Additional rules specified by users or database administrators that define or constrain some aspect of the enterprise. Pearson Education © 2009

Integrity Constraints Entity Integrity In a base relation, no attribute of a primary key can be null. Referential Integrity If foreign key exists in a relation, either foreign key value must match a candidate key value of some tuple in its home relation or foreign key value must be wholly null. Pearson Education © 2009

Entity Integrity The first integrity rule applies to the primary Keys of base relations. Entity integrity : In a base relation, no attribute of a primary key can be null May Aldoayan

Relational Integrity The second integrity rule applies to foreign key. Referential Integrity: If a foreign key exists in a relation, either the foreign key value must match a candidate key value of some tuple in its home relation or the foreign key value must be wholly null. Enterprise constraints: Additional rules specified by the users or DBA of the DB. based on the ways an organization perceives and uses its data (e.g. number of staff working in a branch is at most 20) May Aldoayan

Views Base relation is a named relation corresponding to an entity in the conceptual schema, whose tuples are physically stored in the DB View is a derived relation. Virtual, may not exist, but dynamically derived from one or more base relations. The only information about a view that is stored in the database is its structure. The external model can consist of both conceptual level relations (base relations) and derived views. May Aldoayan

Views STUDENT Base Relation STUDENT_GPA View Dept GPA DOB LName FName StudentNo D001 4.03 15-1-1993 Alsaleh Maha 431671078 3.90 5-6-1992 AlAhmed Reem 430670028 D002 3.50 3-7-1993 AlQahtani Sara 431679802 4.50 10-10-1994 Alotaibi Suha 432784900 D003 4.89 12-3-1992 AlMutairi Lamea 430453772 Base Relation STUDENT_GPA GPA StudentNo 4.03 431671078 3.90 430670028 3.50 431679802 4.50 432784900 4.89 430453772 View May Aldoayan

Purpose of Views It provides a powerful and flexible security mechanism by hiding parts of the DB from certain users. It permits users to access data in a way that is customized to their needs, so that the same data can be seen by different users in different ways, at the same time. It can simplify complex operations. It allow you to work with data from different tables simultaneously. Supports logical data independence May Aldoayan

Updating Views All updates to a base relation should be immediately reflected in all views that reference that base relation. All updates to a view should be reflected in the underlying base relation, under the following rules: Updates are allowed through a view defined using a simple query involving a single base relation & containing either the PK or a CK of the base relation Update are NOT allowed through views involving multiple base relations Updates are not allowed through views involving aggregation or grouping operations May Aldoayan