RELATIONAL DATA MODEL - 1

Slides:



Advertisements
Similar presentations
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Advertisements

Relations The Relational Data Model John Sieg, UMass Lowell.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
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: >
Thomas Connolly and Carolyn Begg’s
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.
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.
CS370 Spring 2007 CS 370 Database Systems Lecture 7 The Relational model.
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.
1 The Relational Data Model, Relational Constraints, and The Relational Algebra.
Chapter 4 The Relational Model.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
Database Management COP4540, SCS, FIU Relational Model Chapter 7.
The Relational Data Model and Relational Database Constraints
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.
Ihr Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
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.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
12/2/2015CPSC , CPSC , Lecture 41 Relational Model.
1 CS 430 Database Theory Winter 2005 Lecture 4: Relational Model.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
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.
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.
Relational Model Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 3.
4/20/2018.
Database Constraints Ashima Wadhwa.
Chapter 2: Relational Model
The Relational Data Model and Relational Database Constraints
RELATION.
Database Design The Relational Model Text Ch5
376a. Database Design Dept. of Computer Science Vassar College
The Relational Database Model
The Relational Data Model and Relational Database Constraints
Data Base System Lecture 6: Relational Model
Chapter 3 The Relational Model.
Chapter 4 The Relational Model Pearson Education © 2009.
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
Chapter 4 The Relational Model Pearson Education © 2009.
DATABASE SYSTEM.
Database Management System
Chapter 4+17 The Relational Model Pearson Education © 2014.
Chapter 4 The Relational Model Pearson Education © 2009.
CS4222 Principles of Database System
12/7/2018.
Database Systems The Basic (Flat) Relational Model
The Relational Model Transparencies
Chapter 4 The Relational Model Pearson Education © 2009.
The Relational Data Model and Relational Database Constraints
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 2: Intro to Relational Model
Database Design: Relational Model
Design tools and techniques for a relational database system
4/8/2019.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 3 The Relational Model
Presentation transcript:

RELATIONAL DATA MODEL - 1 November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 Objectives Terminology + Characteristics of Relations + Relational Data Model Notations + Key constraints + Others Constraints + November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 - 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 a set of allowable values for one or more attributes. Tuple is a row of a relation. Degree is a number of attributes in a relation. Cardinality is a number of tuples in a relation. Relational Database is a collection of relations. 8 November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 - Terminology A relation is a table with columns and rows. Relation name Columns or Attributes t2[DOB] STUDENT ID NAME NAT_ID DOB DEPTCODE 201111 KHALED 1111111111 16-05-1984 ICS 202222 ADEL 2222222222 23-09-1984 COE 203333 AHMED 3333333333 11-08-1984 COE 211111 HASSAN 4444444444 23-10-1985 SWE 204444 MUSTAFA 55555555555 16-11-1984 ICS Cardinality Rows or Tuples Degree November 23, 2019 DB: Relational Data Model - 1

- Characteristics of Relations Each relation in the same relational database schema has a distinct name Each value in a tuple is atomic Each attribute in a relation has a distinct name. Values of an attribute are all from the same domain. Each tuple is distinct. Order of attributes has no significance. Order of tuples has no significance, theoretically. November 23, 2019 DB: Relational Data Model - 1

- Relational Data Model Notations The letters Q, R, S denote the abstract relation names. R(A1, A2, A3, …., An) denotes a relation schema R of degree n. Example: STUDENT(Name, Id, Phone, Address, Mobile, DOB) Both t[Ai] and t.Ai refers to the value vi in t for attribute Ai Example: in second tuple, both t[name] and t.name refers to “Adel” Dom(DEPTCODE) = {‘COE’,’ICS’,’SWE’} November 23, 2019 DB: Relational Data Model - 1

Relation’s Definition Relation: A relation is a subset of Cartesian product of all domains R(r)  Dom(A1) x dom(A2) x …… x Dom(An) Where A1, A2, …., An represent attributes of a relation r. Evaluation: Given A1 = {1, 2}, A2 = {a}, A3 = {x, y} Then relation X = {(1, a, y), (2, a, x), (2, a, y)}; 3 tuples of a relation is a subset of Y = Dom(A1) x dom(A2) x Dom(A3) = {(1, a, x), (1, a, y), (2, a, x), (2, a, y)} Note: Degree of a relation is the number of attributes, in above case degree of relation is 3. Alternate Definition of Relation For each tuple ti is a mapping from R to D Where D = Dom(A1)  Dom(A2) …  Dom(An) And t[Ai]  Dom(Ai) Then a tuple can be considered as attribute and value. For example: The following representation shows a tuple definition t = <(id, 21587), (Name, Muhammad,), (Hphone, Null), (Wphone, 866-1141)> November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 Example Evaluate Cartesian product of the following relations A & B: 1 2 3 a b c A = 4 5 6 B = x y z 7 8 9 1 2 3 a b c 1 2 3 x y z 4 5 6 a b c A x B= 4 5 6 x y z 7 8 9 a b c 7 8 9 x y z November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 - Key Constraints Superkey + Candidate Key + Primary Key + Composite Keys + Alternate Key + Foreign Key + November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 -- Superkey An Attribute or a set of attributes that uniquely identify a tuple within a relation. Example: STU_ID, NAME, NAT_ID, DOB, DEPTCODE STU_ID, NAME, NAT_ID STU_ID NAT_ID STUDENT STU_ID NAME NAT_ID DOB DEPTCODE November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 -- Candidate Key A superkey (K) such that no proper subset is a superkey within the relation. In each tuple of R, the values of K uniquely identify that tuple (uniqueness). No proper subset of K has the uniqueness property (irreducibility). Example: STU_ID NAT_ID STUDENT STU_ID NAME NAT_ID DOB DEPTCODE STU_ID is a candidate key alone because {STU_ID} is a subset of X = {STU_ID, NAT_ID} and X do not has uniqueness property, X is not candidate key but X is super key. November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 -- Candidate Key – cont. Interested in SK for which no proper subset a SK. Example-1: Customer(cname, natid, address, city) cname, address, city can be duplicated individually.   The following combinations distinguish customer records or tuples.  {cname, address} {natid} {natid, cname}  As {natid}  {natid, cname}, then {natid, cname} is not candidate key cname is not SK because several cname might have the same name. Example-2: Branch(branch-name, assets, branch-city) SK: {branch-name}, {branch-name, branch-city}; PK: {branch-name} Candidate Key: {branch-name} because {branch-name}  {branch-name, branch-city} {branch-city} is not SK because two different branches can be in same city. Exercise: Course(cid, cname, deptno) Semester(sid, syear, startdate) ClassAllocation(sid, cid, sec#, building#, room#) Identify Superkeys, candidate keys, alternate keys of each of the above relations November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 -- Primary Key PK is a candidate key selected to identify tuples uniquely within a relation. A primary key is a minimal identifier that is used to identify tuples uniquely. This means that no subset of the primary key is sufficient to provide unique identification of tuples. NULL value is not allowed in primary key attribute. Example: STU_ID (Practically PK must have UNIQUE, NOT NULL, INDEXED on an attribute) STUDENT STU_ID NAME NAT_ID DOB DEPTCODE November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 -- Composite Keys Combination of primary keys of selected attributes gives concept of composite key. composite key is a extended form of primary key Example: {SID, CID, SEC#} COURSE-ALLOCATION SID CID SEC# BUILDING# ROOM# Alternatively, for all semesters SEM-ALLOCAT(SID, SEMID, CID, SEC#, BUILDING#, ROOM#) Following is not valid because duplicate rows and blank columns can be possible SEM-ALLOCAT(ID, SID, SEMID, CID, SEC#, BUILDING#, ROOM#) November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 November 23, 2019 DB: Relational Data Model - 1

-- Alternate Key or Secondary Key candidate keys that are not selected to be the primary key. Example: NAT_ID STUDENT STU_ID NAME NAT_ID DOB DEPTCODE November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 -- Foreign Key An attribute or a set of attributes within one relation that matches the candidate key (or PK) of some (possibly the same) relation. DEPARTMENT DEPTCODE DEPTNAME Foreign key STUDENT STU_ID NAME NAT_ID DOB DEPTCODE November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 -- Foreign Key cont. Deptno is a PK in DEPT table* Empno is a PK in EMP table Deptno is a FK in EMP table* (it references to an attribute Deptno of DEPT table) NOTE: An attribute within one relation that matches the key (Primary/same) in the same relation, is called recursive relation November 23, 2019 DB: Relational Data Model - 1

DB: Relational Data Model - 1 - Other Constraints Null: Represents a value of an attribute that is currently unknown or is no applicable for this tuple, means nothing. Entity integrity Constraint: In a base relation, no attribute of a primary key can be null. Referential Integrity Constraint: If a foreign key exists in a relation, either the foreign key value must match a candidate key (or PK) value of some tuple in its home relation or the foreign key value must be wholly null. Domain Constraint: Specifies that the value of attribute A must be an atomic value from the domain DOM(A). Additional Constraints: Default, NOT NULL, UNIQUE, CHECK; Business Constraints using DB triggers and client’s programming November 23, 2019 DB: Relational Data Model - 1