Relational Data Model DeSiaMore Powered by DeSiaMore.

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
Chapter 5 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Database Systems Chapter 5 ITM 354. Chapter Outline Relational Model Concepts Relational Model Constraints and Relational Database Schemas Update Operations.
Chapter 5 The Relational Data Model and Relational Database Constraints.
CS 405G: Introduction to Database Systems Lecture 4: Relational Model Instructor: Chen Qian.
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 2-1 Data Models Example: A relation.
Database Systems Relational Model Concepts Toqir Ahmad Rana Database Management Systems 1 Lecture 17.
Chapter 5 Relational Model Concepts Dr. Bernard Chen Ph.D. University of Central Arkansas.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
The Relational Data Model 1.Relational Model Concepts 2.Characteristics of Relations 3.Relational Integrity Constraints 3.1Key Constraints 3.2Entity Integrity.
Chapter 4 Rational data model. Chapter 5 Rational data model Chapter 4 Rational data model.
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
CPT-S Topics in Computer Science Big Data
CG084&085 / / 1 The Relational Data Model Properties of Relations Keys and Constraints.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and SQL.
Topic 5 The Relational Data Model and Relational Database Constraints Faculty of Information Science and Technology Mahanakorn University of Technology.
Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 5 The Relational Data Model.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
The Relational Data Model and Relational Database Constraints
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1 Week4 Relational Model and Relational Database Constraints Relational Model Concepts.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
1 CSE 480: Database Systems Lecture 5: Relational Data Model.
METU Department of Computer Eng Ceng 302 Introduction to DBMS The Relational Data Model and Relational Database Constraints by Pinar Senkul resources:
Ihr Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj RM/SQL Lecture 1 ©Akhilesh Bajaj, 2000, 2002, 2003, All.
Chapter 6 The Relational Data Model and the Relational Algebra.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 The Basic 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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
Chapter 5 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 5 The Relational Data Model and Relational Database Constraints Slide 1- 1.
The Relational Data Model and Relational Database Constraints
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
The Relational Data Model and Relational Database Constraints.
4/28/2017 Chapter 5 The Relational Data Model and Relational Database Constraints.
Chapter 3 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints تنبيه.
Lecture # 11 & 12 (First Exam) Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
Copyright © 2004 Pearson Education, Inc.
4/20/2018.
Lecture # 13 (After 1st Exam)
Relational Integrity Constraints
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
CS4222 Principles of Database System
12/7/2018.
The Relational Data Model and Relational Database Constraints
2/28/2019 Chapter 5 The Relational Data Model and Relational Database Constraints.
4/8/2019.
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
5/12/2019.
Copyright © 2004 Pearson Education, Inc.
CS 405G: Introduction to Database Systems
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
Presentation transcript:

Relational Data Model DeSiaMore Powered by DeSiaMore

What is a Data Model? It is a collection of conceptual tools for describing data, data relationships, data semantics and consistency constraints. Essentially answers the following questions: - What is data? - How are the data related to each other? - How can we query the data and change it? - How do we ensure that the data represents a correct view of the real world (data integrity)? Examples of data models include the relational model, the ER model, the network model and the hierarchical model. The network and hierarchical models are found on older mainframe systems (usually in large organizations). DeSiaMore Powered by DeSiaMore

Basics of the Relational Model Primary model used today for data-processing applications Database systems like Oracle, Sybase, Informix, etc. support this model. Has strong theory associated with it. Proposed in 1970-71 and became mainstream in the early 1980-s onwards. Still the most robust model out there, many experts predict it will be around for tens of years more. DeSiaMore Powered by DeSiaMore

Invented by Relational data model was invented by Edgar F. Codd Subsequently maintained and developed by Chris Date and Hugh Darwen among others The relational data model is based on the predicate logic and set theory of mathematics. Codd used mathematical n-ary relations as a base to represent data, which is a subset of the Cartesian product of n sets. Codd DeSiaMore Powered by DeSiaMore Date

Relational Model Concepts The relational Model of Data is based on the concept of a Relation. A Relation is a mathematical concept based on the ideas of sets. The strength of the relational approach to data management comes from the formal foundation provided by the theory of relations. We review the essentials of the relational approach in this chapter. DeSiaMore Powered by DeSiaMore

Basics of the Relational Model Represent data as a two-dimensional table called a relation DeSiaMore Powered by DeSiaMore

Basics of the Relational Model A database represents information about the enterprise. Information is structured, so as to be easy to store, retrieve and modify. In the relational model, the information is structured by means of a relational schema. A relational schema consists of the table names (also called relation names), the column names (or attribute names), the primary keys of each table and a few more objects we will study. In the ER module, we learnt how to capture user requirements in the ER model, and to map this to a simple relational schema. DeSiaMore Powered by DeSiaMore

INFORMAL DEFINITIONS RELATION: A table of values A relation may be thought of as a set of rows. A relation may alternately be though of as a set of columns. Each row represents a fact that corresponds to a real-world entity or relationship. Each row has a value of an item or set of items that uniquely identifies that row in the table. Sometimes row-ids or sequential numbers are assigned to identify the rows in the table. Each column typically is called by its column name or column header or attribute name. DeSiaMore Powered by DeSiaMore

FORMAL DEFINITIONS A Relation may be defined in multiple ways. The Schema of a Relation: R (A1, A2, .....An) Relation schema R is defined over attributes A1, A2, .....An For Example - CUSTOMER (Cust-id, Cust-name, Address, Phone#) Here, CUSTOMER is a relation defined over the four attributes Cust-id, Cust-name, Address, Phone#, each of which has a domain or a set of valid values. For example, the domain of Cust-id is 6 digit numbers. DeSiaMore Powered by DeSiaMore

FORMAL DEFINITIONS A tuple is an ordered set of values Each value is derived from an appropriate domain. Each row in the CUSTOMER table may be referred to as a tuple in the table and would consist of four values. <632895, "John Smith", "101 Main St. Atlanta, GA 30332", "(404) 894-2000"> is a tuple belonging to the CUSTOMER relation. A relation may be regarded as a set of tuples (rows). Columns in a table are also called attributes of the relation. DeSiaMore Powered by DeSiaMore

FORMAL DEFINITIONS A domain has a logical definition: e.g., “USA_phone_numbers” are the set of 10 digit phone numbers valid in the U.S. A domain may have a data-type or a format defined for it. The USA_phone_numbers may have a format: (ddd)-ddd-dddd where each d is a decimal digit. E.g., Dates have various formats such as monthname, date, year or yyyy-mm-dd, or dd mm,yyyy etc. An attribute designates the role played by the domain. E.g., the domain Date may be used to define attributes “Invoice-date” and “Payment-date”. DeSiaMore Powered by DeSiaMore

FORMAL DEFINITIONS Let S1 = {0,1} Let S2 = {a,b,c} Let R  S1 X S2 Then for example: r(R) = {<0,a> , <0,b> , <1,c> } is one possible “state” or “population” or “extension” r of the relation R, defined over domains S1 and S2. It has three tuples. DeSiaMore Powered by DeSiaMore

DEFINITION SUMMARY Informal Terms Formal Terms Table Relation Column Attribute/Domain Row Tuple Values in a column Domain Table Definition Schema of a Relation Populated Table Extension DeSiaMore Powered by DeSiaMore

Example - Figure DeSiaMore Powered by DeSiaMore

Example of a relational schema PROFESSORS(fac_id, f_name, research_interest) COURSES(c_num, c_name, num_credits) TEACH(fac_id, c-num) Once we have a schema, the actual information is stored in the form of rows (tuples). Each row represents a “piece” or record of information that represents a part of the real world. Example of rows: PROFESSORS Important A table can never have duplicate rows. Fac_id F_name Research_interest Rows or records or tuples 1 Akhilesh Bajaj Information Systems 2 Sudha Ram Database Modeling DeSiaMore Powered by DeSiaMore

Relational Integrity Constraints Constraints are conditions that must hold on all valid relation instances. There are three main types of constraints: Key constraints Entity integrity constraints Referential integrity constraints DeSiaMore Powered by DeSiaMore

Key Constraints Superkey of R: A set of attributes SK of R such that no two tuples in any valid relation instance r(R) will have the same value for SK. That is, for any distinct tuples t1 and t2 in r(R), t1[SK]  t2[SK]. . 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.. DeSiaMore Powered by DeSiaMore

Key Constraints Also a superkey can be said as a set of attributes in a table, such that no 2 rows can have the same values when we consider all the attributes in the superkey together. E.g., (s_id, name, address, GPA, age), (s_id, name), (s_id, address), (s_id, GPA) are all sets of attributes that are examples of superkeys for the table STUDENTS. A candidate key is a superkey of a table such that no subset of these attributes is also a superkey. E.g., (s_id) is a candidate key of STUDENTS. DeSiaMore Powered by DeSiaMore

Key Constraints A table can have several superkeys and more than one of these may be candidate keys. A primary key is selected from these candidate keys. Usually, if the table represents real-world objects, we designate an id as a primary key. If a relation has several candidate keys, one is chosen arbitrarily to be the primary key. The primary key attributes are underlined DeSiaMore Powered by DeSiaMore

Superkeys, Candidate Keys, Primary Keys All possible attribute sets of a table T All possible superkeys of a table T One set of attributes that make up the primary key of table T All possible candidate keys of a table T DeSiaMore Powered by DeSiaMore

Key Constraints DeSiaMore Powered by DeSiaMore

t[PK]  null for any tuple t in r(R) Entity Integrity Relational Database Schema: A set S of relation schemas that belong to the same database. S is the name of the database. S = {R1, R2, ..., Rn} Entity Integrity: The primary key attributes PK of each relation schema R in S cannot have null values in any tuple of r(R). This is because primary key values are used to identify the individual tuples. t[PK]  null for any tuple t in r(R)  Note: Other attributes of R may be similarly constrained to disallow null values, even though they are not members of the primary key. DeSiaMore Powered by DeSiaMore

Referential Integrity A constraint involving two relations (the previous constraints involve a single relation). Used to specify a relationship among tuples in two relations: the referencing relation and the referenced relation. Tuples in the referencing relation R1 have attributes FK (called foreign key attributes) that reference the primary key attributes PK of the referenced relation R2. A tuple t1 in R1 is said to reference a tuple t2 in R2 if t1[FK] = t2[PK]. A referential integrity constraint can be displayed in a relational database schema as a directed arc from R1.FK to R2. DeSiaMore Powered by DeSiaMore

5.7 DeSiaMore Powered by DeSiaMore

Referential Integrity Constraint Statement of the constraint The value in the foreign key column (or columns) FK of the the referencing relation R1 can be either: (1) a value of an existing primary key value of the corresponding primary key PK in the referenced relation R2,, or.. (2) a null. In case (2), the FK in R1 should not be a part of its own primary key. DeSiaMore Powered by DeSiaMore

In-Class Exercise (Taken from Exercise 5.15) 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. DeSiaMore Powered by DeSiaMore