CSE 132A Database Systems Principles

Similar documents
Chapter 5. Relational Model Concepts 5/2/2008. Chapter Outline. Relational Database Constraints

Chapter 5. Relational Model Concepts 9/4/2012. Chapter Outline. The Relational Data Model and Relational Database Constraints

The Relational Data Model and Relational Database Constraints

Chapter 5. The Relational Data Model and Relational Database Constraints. Slide 5-١. Copyright 2007 Ramez Elmasri and Shamkant B.

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 5-1

01/01/2017. Chapter 5: The Relational Data Model and Relational Database Constraints: Outline. Chapter 5: Relational Database Constraints

The Basic (Flat) Relational Model. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5-1

A database consists of several tables (relations) AccountNum

Chapter 2: Relational Model

CS 377 Database Systems

Let s briefly review important EER inheritance concepts

UNIT 2 RELATIONAL MODEL

Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

Chapter 2: Relational Model

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

CS275 Intro to Databases

A database can be modeled as: + a collection of entities, + a set of relationships among entities.

CS 2451 Database Systems: Relational Data Model

Relational Model. Nisa ul Hafidhoh

Relational Data Model. Christopher Simpkins

DATABASE TECHNOLOGY - 1DL124

PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore ) Department of MCA. Solution Set - Test-II

CS34800 Information Systems. The Relational Model Prof. Walid Aref 29 August, 2016

Database System Concepts

Chapter 3: Relational Model

Relational Model Concepts

DATABASE DESIGN I - 1DL300

Chapter 4. The Relational Model

ECE 650 Systems Programming & Engineering. Spring 2018

CSC 742 Database Management Systems

DATABASE TECHNOLOGY. Spring An introduction to database systems

COSC344 Database Theory and Applications. σ a= c (P) Lecture 3 The Relational Data. Model. π A, COSC344 Lecture 3 1

CS2300: File Structures and Introduction to Database Systems

Chapter 2 Introduction to Relational Models

CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E)

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Relational Databases Fall 2017 Lecture 1

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Introduction to Relational Database Systems Fall 2016 Lecture 1

CS530 Database Architecture Models. Database Model. Prof. Ian HORROCKS. Dr. Robert STEVENS. and Design The Relational

Chapter 2: Intro to Relational Model

Supplier-Parts-DB SNUM SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens

customer = (customer_id, _ customer_name, customer_street,

THE RELATIONAL DATA MODEL CHAPTER 3 (6/E) CHAPTER 5 (5/E)

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

We shall represent a relation as a table with columns and rows. Each column of the table has a name, or attribute. Each row is called a tuple.

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Relational Databases Fall 2017 Lecture 7

The Relational Data Model. Data Model

CS425 Fall 2016 Boris Glavic Chapter 2: Intro to Relational Model

Database Systems Relational Model. A.R. Hurson 323 CS Building

Relational Database Systems Part 01. Karine Reis Ferreira

ACS-3902 Fall Ron McFadyen 3D21 Slides are based on chapter 5 (7 th edition) (chapter 3 in 6 th edition)

Chapter 6: Relational Database Design

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions.

Relational Data Model

Running Example Tables name location

CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E)

DBMS: AN INTERACTIVE TUTORIAL

Introduction to Relational Databases. Introduction to Relational Databases cont: Introduction to Relational Databases cont: Relational Data structure

CSCI1270 Introduction to Database Systems

The Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC)

The Relational Data Model and Relational Database Constraints

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

Lecture 14 of 42. E-R Diagrams, UML Notes: PS3 Notes, E-R Design. Thursday, 15 Feb 2007

DATABASE TECHNOLOGY - 1MB025 (also 1DL029, 1DL300+1DL400)

The Relational Model of Data (ii)

The Relational Data Model (ALL the Vocabulary)

Comp 5311 Database Management Systems. 2. Relational Model and Algebra

CS352 - DATABASE SYSTEMS. To give you experience with developing a database to model a real domain

Relational Model. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011

Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to

CMSC 424 Database design Lecture 4: Relational Model ER to Relational model. Book: Chap. 2 and 6. Mihai Pop

The data structures of the relational model Attributes and domains Relation schemas and database schemas

Relational Model and Relational Algebra. Rose-Hulman Institute of Technology Curt Clifton

Relational Algebra. Relational Algebra. 7/4/2017 Md. Golam Moazzam, Dept. of CSE, JU

Upon completion of this Unit, students will be introduced to the following

Introduction to Database Systems. The Relational Data Model

Introduction to Database Systems. The Relational Data Model. Werner Nutt

Chapter 14 Outline. Normalization for Relational Databases: Outline. Chapter 14: Basics of Functional Dependencies and

e e Conceptual design begins with the collection of requirements and results needed from the database (ER Diag.)

Introduction to Data Management. Lecture #4 (E-R Relational Translation)

Relational Model and Relational Algebra

CSIT5300: Advanced Database Systems

Chapter 7: Relational Database Design

Who, where, when. Database Management Systems (LIX022B05) Literature. Evaluation. Lab Sessions. About this course. After this course...

The Relational Model

Relational Model. CS 377: Database Systems

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

CS 4400 Exam 2 ANSWER KEY

Relational Database design. Slides By: Shree Jaswal

CS352 - DATABASE SYSTEMS

Database Management System 9

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

U1. Data Base Management System (DBMS) Unit -1. MCA 203, Data Base Management System

Example: specific person, company, event, plant

INF1383 -Bancos de Dados

In This Lecture. The Relational Model. The Relational Model. Relational Data Structure. Unnamed and named tuples. New thing:scheme (and attributes)

Databases. Jörg Endrullis. VU University Amsterdam

Functional Dependencies & Normalization for Relational DBs. Truong Tuan Anh CSE-HCMUT

Relational data model

Transcription:

CSE 132A Database Systems Principles Prof. Alin Deutsch RELATIONAL DATA MODEL Some slides are based or modified from originals by Elmasri and Navathe, Fundamentals of Database Systems, 4th Edition 2004 Pearson Education, Inc. and Database System Concepts, McGraw Hill 5th Edition 2005 Silberschatz, Korth and Sudarshan and Prof. Sergio Lifschitz PUC-Rio, Brazil Slide 1-34

Data Models Data Model: A set of concepts to describe the structure of a database, and certain constraints that the database should obey. Data Model Operations: Operations for specifying database retrievals and updates by referring to the concepts of the data model. Operations on the data model may include basic operations and user-defined operations. Slide 2-34

Categories of data models Conceptual (high-level, semantic) data models: Provide concepts that are close to the way many users perceive data. Also called entity-based or object-based data models. Physical (low-level, internal) data models: Provide concepts that describe details of how data is stored. Implementation (representational) data models: Provide concepts that fall between the above two, balancing user views with some computer storage details. Slide 3-34

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. Slide 4-34

Example of a Relation Slide 5-34

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. Slide 6-34

Relation Schema A 1, A 2,, A n are attributes R = (A 1, A 2,, A n ) is a relation schema e.g. Customer_schema = (customer_name, customer_street, customer_city) r(r) is a relation on the relation schema R Example: customer (Customer_schema) Slide 7-34

Relation Instance The current values (relation instance) of a relation are specified by a table An element t of r is a tuple, represented by a row in a table customer_name customer_street customer_city attributes (or columns) Jones Smith Curry Lindsay Main North North Park Harrison Rye Rye Pittsfield tuples (or rows) customer Slide 8-34

Database A database consists of multiple relations Information about an enterprise is broken up into parts, with each relation storing one part of the information account : stores information about accounts depositor : stores information about which customer owns which account customer : stores information about customers Storing all information as a single relation such as bank (account_number, balance, customer_name,..) is possible but results in repetition of information and the need for null values Slide 9-34

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. Slide 10-34

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. Slide 11-34

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/format defined for it. The USA_phone_numbers may have a format: (ddd)-ddddddd where each d is a decimal digit. e.g., Dates have various formats such as month_name, 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. Slide 12-34

FORMAL DEFINITIONS The relation is formed over the cartesian product of the sets; each set has values from a domain; that domain is used in a specific role which is conveyed by the attribute name. For example, attribute Cust-name is defined over the domain of strings of 25 characters. The role these strings play in the CUSTOMER relation is that of the name of customers. Given R(A 1, A 2,..., A n ) r(r) dom (A 1 ) X dom (A 2 ) X...X dom(a n ) R: schema of the relation r of R: a specific "value" or population of R. R is also called the intension of a relation r is also called the extension of a relation Slide 13-34

FORMAL DEFINITIONS Let S1 = {0,1} and S2 = {a,b,c} Let R S1 X S2 Then r(r) = {<0,a>, <0,b>, <1,c> } is one possible state, population or extension r of the relation R, defined over domains S1 and S2. It has three tuples. Slide 14-34

FORMAL DEFINITIONS Given sets D 1, D 2,. D n a relation r is a subset of D 1 x D 2 x x D n A relation is a set of n-tuples (a 1, a 2,, a n ) where each a i D i Example: customer_name = {Jones, Smith, Curry, Lindsay} customer_street = {Main, North, Park} customer_city = {Harrison, Rye, Pittsfield} Then r = { (Jones, Main, Harrison), (Smith, North, Rye), (Curry, North, Rye),(Lindsay, Park, Pittsfield) } is a relation over customer_name x customer_street x customer_city Slide 15-34

Attribute Types Each attribute of a relation has a name The set of allowed values for each attribute is called the domain of the attribute Attribute values are (normally) required to be atomic; that is, indivisible Note: multivalued attribute values are not atomic Note: composite attribute values are not atomic The special value null is a member of every domain Slide 16-34

DEFINITION SUMMARY Informal Terms Formal Terms Table Column Row Values in a column Table Definition Populated Table Relation Attribute/Domain Tuple Domain Schema of a Relation Extension Slide 17-34

Example Slide 18-34

CHARACTERISTICS OF RELATIONS Ordering of tuples in a relation r(r): The tuples are not considered to be ordered, even though they appear to be in the tabular form. Ordering of attributes in a relation schema R (and of values within each tuple): We will consider the attributes in R(A 1, A 2,..., A n ) and the values in t=<v 1, v 2,..., v n > to be ordered. (However, a more general alternative definition of relation does not require this ordering). Values in a tuple: All values are considered atomic (indivisible). A special null value is used to represent values that are unknown or inapplicable to certain tuples. Slide 19-34

Relations are Unordered Slide 20-34

Notation: CHARACTERISTICS OF RELATIONS - We refer to component values of a tuple t by t[a i ] = v i (the value of attribute A i for tuple t). Similarly, t[a u, A v,..., A w ] refers to the subtuple of t containing the values of attributes A u, A v,..., A w, respectively. Slide 21-34

CHARACTERISTICS OF RELATIONS Slide 22-34

Relational Integrity Constraints Constraints are conditions that must hold on all valid relation instances. There are three main types of constraints: 1. Key constraints 2. Entity integrity constraints 3. Referential integrity constraints Slide 23-34

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]. Key of R: A "minimal" superkey; that is, a superkey K such that removal of any attribute from K results in a set of attributes that is not a superkey. 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. If a relation has several candidate keys, one is chosen arbitrarily to be the primary key. The primary key attributes are underlined. Slide 24-34

Key Constraints Slide 25-34

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 = {R 1, R 2,..., R n } 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 PK 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. Slide 26-34

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 R 1 have attributes FK (called foreign key attributes) that reference the primary key attributes PK of the referenced relation R 2. A tuple t 1 in R 1 is said to reference a tuple t 2 in R 2 if t 1 [FK] = t 2 [PK]. A referential integrity constraint can be displayed in a relational database schema as a directed arc from R 1.FK to R 2. Slide 27-34

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

Other Types of Constraints Semantic Integrity Constraints: based on application semantics and cannot be expressed by the model per se - e.g., the max. no. of hours per employee for all projects he or she works on is 56 hrs per week - A constraint specification language may have to be used to express these - SQL-99 allows triggers and ASSERTIONS to allow for some of these Slide 29-34

Slide 30-34

Slide 31-34

Slide 32-34

Update Operations on Relations INSERT a tuple. DELETE a tuple. MODIFY a tuple. Integrity constraints should not be violated by the update operations. Several update operations may have to be grouped together. Updates may propagate to cause other updates automatically. This may be necessary to maintain integrity constraints. Slide 33-34

Update Operations on Relations In case of integrity violation, several actions can be taken: Cancel the operation that causes the violation (REJECT option) Perform the operation but inform the user of the violation Trigger additional updates so the violation is corrected (CASCADE option, SET NULL option) Execute a user-specified error-correction routine Slide 34-34