Chapter 3 CIS 458 Sungchul Hong

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

CSC271 Database Systems Lecture # 5. Summary: Previous Lecture  Database languages  Functions of a DBMS  DBMS environment  Data models and their categories.
Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College.
Logical Database Design
The Relational Model System Development Life Cycle Normalisation
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Lesson II The Relational Model © 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.
Chapter 5 The Relational Data Model and Relational Database Constraints.
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.
LOGICAL DATABASE DESIGN
Database Systems Relational Model Concepts Toqir Ahmad Rana Database Management Systems 1 Lecture 17.
Database Architecture The Relational Database Model.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
Chapter 3 Relational Model Chapter 4 in Textbook.
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
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 5 The Relational Data Model.
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.
METU Department of Computer Eng Ceng 302 Introduction to DBMS The Relational Data Model and Relational Database Constraints by Pinar Senkul resources:
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
Chapter 9 Methodology - Logical Database Design Chapter 16 in Textbook.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
Chapter 8 Methodology - Conceptual Database Design Chapter 15 in Textbook.
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.
1 E-R Model (II) Keys To identify records in a table Candidate Key Primary Key Alternate Key Composite Key.
1 Chapter 17 Methodology - Local Logical Database Design.
Entity-Relationship Model Chapter 3 II COSC 457 Sungchul Hong.
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.
Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.
Modelling Methodologies Chapter 16, 17, 18. Modeling Methodologies2 Database Design Physical DB design Logical DB design Conceptual DB design Hardware.
Relational Data Model DeSiaMore Powered by DeSiaMore.
Chapter 5 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
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,
Lecture4: Informal guidelines for good relational design Mapping ERD to Relation Prepared by L. Nouf Almujally Ref. Chapter3 Lecture4 1.
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 3 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Teacher Workshop Database Design Pearson Education © 2014.
Database Design The Relational Model Text Ch5
The Relational Database Model
Relational Integrity Constraints
Data Base System Lecture 6: Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Conceptual Database Design
Chapter 4+17 The Relational Model Pearson Education © 2014.
Chapter 4 The Relational Model Pearson Education © 2009.
Logical Database Design
The Relational Model Transparencies
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
CS 405G: Introduction to Database Systems
Presentation transcript:

Chapter 3 CIS 458 Sungchul Hong The Relational Model Chapter 3 CIS 458 Sungchul Hong

Last Class ERD Entities, Relations, Attributes It is not model specific

This Class Relational Model & Schema Conversion Cartesian product Cf) Hierarchical model Network model Object Oriented Model Cartesian product Integrity Relational integrity Entity integrity

Relational Database Management Systems Dominant data processing software The estimates sales is between $15 billion - $20 billion per year. Relational model In the relational model, all data is logically structured within relations (tables). Each relation has a name and is made up of named attributes (columns) of data. Each tuple (row) contains one value per attribute.

Relational Data Structure The relational model is based on the mathematical concept of a relation. Relation is a table with columns and rows. Attribute: An attribute is a named column of a relation Domain: A domain is the set of allowable values for one or more attributes. Tuple: a tuple is a row of a relation

Relations

Relational Data Structure (2) Degree: The degree of a relation is the number of attributes it contains. n-ary Cardinality: The cardinality of a relation is the number of tuples it contains. Relational database: A collection of normalized relations with distinct relation names.

Mathematical Relations Sets D1 and D2 where D1 = {2, 4} and D2={1, 3, 5}. Cartesian product D1  D2, is the set of all ordered pairs such that the first element is a member of D1 and the second element is a member of D2. D1  D2 ={(2, 1), (2, 3), (2, 5), (4, 1), (4, 3), (4, 5)}

Exercise E1 = {a, b, c} E2 = {3, 4, 5} E1  E2 = {(a,3), (a, 4), (a,5) (b,3), (b, 4), (b,5) (c,3), (c, 4), (c,5)}

Mathematical Relations (2) Any subset of this Cartesian product is a relation. D1= {2, 4} , D2={1, 3, 5} Relation R = {(2, 1), (4, 1)} R = { (x, y) | x  D1, y  D2, and y = 1} You want to find out some records not entire table. S = {(x, y) | x  D1, y  D2, and x= 2y} S = { (2,1) }

Mathematical Relations (3) D1 = {1, 3}, D2 = {2, 4}, D3 = {5, 6} D1  D2  D3 = {(1,2,5), (1,2,6), (1,4,5), (1,4,6) (3,2,5), (3,2,6), (3,4,5), (3,4,6)}

Database Relations Relation Schema: A named relation defined by a set of attribute and domain name pairs. Let A1, A2, …, An be attributes with domain D1, D2, …, Dn. Then the set {A1:D1, A2:D2, …, An:Dn} is a relation schema. A relation R defined by a relation schema S is a set of mappings from the attribute names to their corresponding domains. (A1:d1, A2:d2, … , An:dn) such that d1  D1, d2  D2, … , dn  Dn

Database Relations (2) Example Branch table {branchNo: B005, street: 22Deer Rd, city: London, postcode: SW1 4EH} Relational instance Relational database schema: A set of relation schemas each with a distinct name. If R1, R2, … , Rn are a set of relation schemas, then we can write the relational database schema or relational schema R, as: R= {R1, R2, …, Rn}

Branch A3 A4 A1 A2 D1 D2 Domain D3 D4 BranchNo street city postcode 22 Deer Rd London SW14EH B007 16 Argyll St. Aberdeen AB2 3SU B003 163 Main St Glasgow G11 9QX B004 32 Manse Rd Bristol BS99 1NZ B002 56 Clover Dr. NW10 6EU D1 D2 Domain D3 D4

R1 R2 R3 R4 R5 R6 R={R1, R2, R3, R4, R5, R6}

Properties of Relations (1/2) The relation has a name that is distinct from all other relation names in the relational schema. Each cell of the relation contains exactly one atomic value. Each attribute has a distinct name. The values of an attribute are all from the same domain.

Properties of Relations (2/2) Each tuple is distinct: there are no duplicate tuples. The order of attributes has no significance. Practically has significance. The order of tuples has no significance, theoretically. Normalized or first normal form

Relational Keys Superkey: An attribute, or set of attributes, that uniquely identifies a tuple within a relation. Candidate key: A superkey such that no proper subset is a superkey within the relation. Uniqueness (need semantic information) Irreducibility

Example: The CAR relation schema: CAR(State, Reg#, SerialNo, Make, Model, Year) has two keys Key1 = {State, Reg#}, Key2 = {SerialNo}, which are also superkeys. {SerialNo, Make} is a superkey but not a key.

Relational Keys (2) Primary Key: The candidate key that is selected to identify tuples uniquely within the relation. The candidate keys that are not selected to be the primary key are called alternate keys. Foreign key: An attribute, or set of attributes, within one relation that matches the candidate key of some relation. When an attribute appears in more than one relation, its appearance usually represents a relationship between tuples of the two relations.

Schema Conversion Create a table for each entity Relation Attribute 1:1 choose one side and put a foreign key 1:* put a foreign key in many side *:* create a table for the relation Relation *:* create a table Ternary or higher degree Attribute Multi-valued attribute

(1..1) (0..1) Staff(staffNo, name, position, salary, branchNo) Branch(branchNo, street, city, postcode) Telephone (branchNo, telNo) OR Staff(staffNo, name, position, salary,) Branch(branchNo, street, city, postcode, staffNo) Telephone (branchNo, telNo)

(1..*) (1..1) Staff(staffNo, name, position, salary, manages, belongs) Branch(branchNo, street, city, postcode) Telephone (branchNo, telNo) Domain [manages]= Branch.branchNo Domain [belongs] = Branch.branchNo

Staff (1..*) Branch (1..1) staffNo fName lName manages sex DOB salary branchNo SL21 John White B005 M Oct/1/45 30000 SG37 Ann Beech F Nov/10/60 12000 B003 SG14 David Ford Mar/24/58 18000 SA9 Mary Howe 19/Feb/70 9000 B007 SG5 Susan Brand Jun/3/40 24000 SL41 Julie Lee Jun/13/65 (1..*) Branch BranchNo street city postcode B005 22 Deer Rd London SW14EH B007 16 Argyll St. Aberdeen AB2 3SU B003 163 Main St Glasgow G11 9QX B004 32 Manse Rd Bristol BS99 1NZ B002 56 Clover Dr. NW10 6EU (1..1)

Newspaper(newspaperName) PropertyForRent NewsPaper ◄Advertises newsPaperName {PK} propertyNo{PK} Street City Postcode Rooms Rent privateOwnerNo … (1..*) (0..*) dateAdvert Cost PropertyForRent (propertyNo, street, city, postcode, type, rooms, rent, privateOwnerNo, businessOwnerNo, staffNo, branchNo) Newspaper(newspaperName) Advertisement (newspaperName, PropertyNo, dateAdvert, cost)

Exercise Employee Department Project Dependent ◄Supervises Supervisor 0..1 Manages ► Employee SSN{pk} FName MINIT LName BDate Address Sex Salary Department Dnumber{pk} Dname Mgrstartdate Location[1..n] 1..1 1..0 ◄Has 1..* 1..1 1..* 1..1 In Charge of► Supervisee 1..* Works_on ► 1..1 ◄Depend On 0..* 0..* 0..* Project Pnumber{pk} Pname Plocation Dependent Dependent_Name Sex Bdate Relationship

R1 R2 R3 R4 R5 R6 R={R1, R2, R3, R4, R5, R6}

Exercise

Representing Relational Database Schemas DreamHome case study Branch (branchNo, street, city, postcode, manager) Staff (staffNo, fName, lName, position, sex, DOB salary, branchNo, supervisor) PropertyForRent (propertyNo, street, city, postcode, type, rooms, rent, privateOwnerNo, businessOwnerNo, staffNo, branchNo) Client (clientNo, fName, lName, telNo, prefType, maxRent) Registration (clientNo, branchNo, staffNo, dateJoined) Manager(staffNo, branchNo, MgrStartDate, bonus)

Schema Lease (leaseNo, PropertyNo, clientNo) Preference (clientNo, preference) Newspaper(newspaperName) Advertisement (newspaperName, PropertyNo, dateAdvert, cost) PrivateOwner (privateOwnerNo, fName, lName, address, telNo) BusinessOwner (businessOwnerNo, businessName)

Relational Integrity Data Model Definition, manipulative part Domain constraints form restrictions on the set of values allowed for the attributes of relation. Integrity rules Constraints or restrictions that apply to all instances of the database. Entity integrity, referential integrity

Relational Integrity (2) Null represents a value for an attribute that is currently unknown or is not applicable for this tuple. Unknown, incomplete or exceptional data Null is not zero nor white space.

Entity Integrity Base Relation: A named relation corresponding to an entity in the conceptual schema, whose tuples are physically stored in the database. View (Virtual relation) Entity integrity: In a base relation, no attribute of a primary key can be null.

Referential Integrity 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 database administrators of a database. A employee can not work more than 65 hours per week. Salary value must be a positive number.

Views A view is a virtual or derived relation. A relation that does not necessarily exist in its own right, but may be dynamically derived from one or more base relations. Provide a powerful and flexible security mechanism. Customized user data access It can simplify complex operations. Updates are allowed on simple query with a single base relation. Not allowed with multiple base relations. Not allowed with aggregation or grouping operations.

Exercise Chairs► PROFESSOR DEPARTMENT 1..1 0..1 1..1 1..N IS ASSIGNED TO► PROFESSOR(PID, FName, MINIT, LName, DOB, Rank) DEPARTMENT (DID, DName)

Exercise COURSE 1..1 Has▼ o..* ENROLL► SECTION STUDENTS 0..35 1..6 STUDENTS (SID, FName, LName, DOB, Major[1..3], Minor) COURSE (COURSE#, C_Name, Description) SECTION (Section_Num, Max_size)

Painter (Painter_ID, FName, LName) Paining (Painting_ID, Title, Date) Exercise Paint ► (0..*) Displayed (1..1) ► Painter (1,1) (0..*) Painting Gallery Painter (Painter_ID, FName, LName) Paining (Painting_ID, Title, Date) Gallery (Gallery_Name, Location)

Employee (EID, FName, LName) Skill (Skill_Name) Exercise Learn ► 0..* 0..* Employee Skills Expert Level Employee (EID, FName, LName) Skill (Skill_Name)

STUDENTS (SID, FName, LName, DOB) CLASS (CLASS#, C_Name, Description) Exercise Take ► 1..* 0..* Student Classes Grade STUDENTS (SID, FName, LName, DOB) CLASS (CLASS#, C_Name, Description)

Exercise (Recursive and many-to-many) STUDENTS (SID, FName, LName, DOB) COURSE (COURSE#, C_Name, Description) SECTION (Section_Num, Max_size) Has ► 1..1 0..* Course Section 0..* 0..* 0..* Take ▼ Grade ◄Prerequisite 1..* Student

Grade Course# Cname Dept Student Enroll Course Adopt Quarter 1 N Student SSN{pk} Name Major Bdate Enroll Course 1 1 Adopt Quarter Quarter{pk} 1 N Text ISBN{pk} Publisher Author

Exercise Consider the following relations for a database that keeps track of student enrollment in courses and the books adopted for each course: STUDENT(SSN, Name, Major, Bdate) COURSE(Course#, Cname, Dept) ENROLL(SSN, Course#, Quarter, Grade) BOOK_ADOPTION(Course#, Quarter, Book_ISBN) TEXT(Book_ISBN, Book_Title, Publisher, Author) Draw a relational schema diagram specifying the foreign keys for this schema.