CSC 742 Database Management Systems

Similar documents
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

CS 377 Database Systems

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

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

ECE 650 Systems Programming & Engineering. Spring 2018

CS275 Intro to Databases

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

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

The Relational Data Model and Relational Database Constraints

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

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

CSE 132A Database Systems Principles

The Relational Model of Data (ii)

Let s briefly review important EER inheritance concepts

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

CS 2451 Database Systems: Relational Data Model

The Relational Data Model. Data Model

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

Relational data model

Chapter 2 Introduction to Relational Models

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

The Relational Model. Week 2

Mapping ER Diagrams to. Relations (Cont d) Mapping ER Diagrams to. Exercise. Relations. Mapping ER Diagrams to Relations (Cont d) Exercise

The Relational Model

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

Introduction to Data Management. Lecture #5 Relational Model (Cont.) & E-Rà Relational Mapping

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

Relational Model and Relational Algebra

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

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

Database Management Systems. Chapter 3 Part 1

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

Introduction to Database Systems. The Relational Data Model

The Relational Model 2. Week 3

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

CS 4400 Exam 2 ANSWER KEY

The Relational Model. Chapter 3

Relational Data Model. Christopher Simpkins

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

Databases. Jörg Endrullis. VU University Amsterdam

Chapter 2: Intro to Relational Model

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

Relational Model Concepts

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

Chapter 4. The Relational Model

The Relational Data Model (ALL the Vocabulary)

Database Systems ( 資料庫系統 )

CSC 453 Database Technologies. Tanu Malik DePaul University

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

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

CS403- Database Management Systems Solved Objective Midterm Papers For Preparation of Midterm Exam

A database consists of several tables (relations) AccountNum

Review. The Relational Model. Glossary. Review. Data Models. Why Study the Relational Model? Why use a DBMS? OS provides RAM and disk

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

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

Running Example Tables name location

Class Information. Textbooks. Grading. Final Project. Grading. CS 440: Database Management Systems. Instructor:

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.

The Relational Model

Comp 5311 Database Management Systems. 4b. Structured Query Language 3

CompSci 516 Database Systems. Lecture 2 SQL. Instructor: Sudeepa Roy

DBMS. Relational Model. Module Title?

Database Applications (15-415)

The Relational Model. Roadmap. Relational Database: Definitions. Why Study the Relational Model? Relational database: a set of relations

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages

DATABASE TECHNOLOGY - 1DL124

Relational Model. CS 377: Database Systems

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010

Functional Dependencies CS 1270

Where Are We? Next Few Lectures. Integrity Constraints Motivation. Constraints in E/R Diagrams. Keys in E/R Diagrams

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

Lecture 2 SQL. Announcements. Recap: Lecture 1. Today s topic. Semi-structured Data and XML. XML: an overview 8/30/17. Instructor: Sudeepa Roy

DATABASE DESIGN I - 1DL300

The Relational Model and Normalization

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

CS2300: File Structures and Introduction to Database Systems

Refresher: ER-modeling, logical relational model, dependencies. Toon Calders

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615

Lecture 2 SQL. Instructor: Sudeepa Roy. CompSci 516: Data Intensive Computing Systems

Introduction to Database Management Systems

Administrivia. The Relational Model. Review. Review. Review. Some useful terms

Relational Data Model

The Relational Model

CS317 File and Database Systems

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

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

Relational model. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

Chapter 8 INTEGRITY 1

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

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

Relational Model, Relational Algebra, and SQL

Chapter 7 Constraints and Triggers. Spring 2011 Instructor: Hassan Khosravi

Database Systems. Course Administration

Relational Model. CSC 343 Winter 2018 MICHAEL LIUT

The Relational Model Constraints and SQL DDL

Introduction to Database Systems CSE 414

Transcription:

CSC 742 Database Management Systems Topic #5: Relational Model Spring 2002 CSC 742: DBMS by Dr. Peng Ning 1

Motivation A relation is a mathematical abstraction for a table The theory of relations provides an elegant basis for databases Relational databases can be efficiently implemented on current architectures Spring 2002 CSC 742: DBMS by Dr. Peng Ning 2

Relation Model A relation is a table of values Relation Name Student Attribute Name Student ID Class Major Tuple Smith 17 1 CS Brown 8 2 CS Each tuple represents a collection of related data. All values in a column are of the same data type. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 3

Is this a relation? Student Name Student ID Emails Major Smith 17 {smith@csc.ncsu.edu, smith@unity.ncsu.edu, CS smith@eos.ncsu.edu} Brown 8 {brown@unity.ncsu.edu} CS Spring 2002 CSC 742: DBMS by Dr. Peng Ning 4

Domain D A domain of an attribute specifies all possible values the attribute can have. A domain is a set of atomic values. Each value in the domain is indivisible. Often expressed as a data type. Describe the domains of the following attributes US_Phone_number: Age: Social_Security_Number: Name: Spring 2002 CSC 742: DBMS by Dr. Peng Ning 5

Relation Schema A relation schema R(A1... An) describes the intension of a relation R: relation name A1,, An: a list of attributes n: the degree of a relation of this schema. attributes Ai name the roles or columns dom(ai) = Di: the domain of Ai. attributes are distinct but may share their domain Spring 2002 CSC 742: DBMS by Dr. Peng Ning 6

An Example Schema Student(Name, SSN, HomePhone, Address, OfficePhone, Age, GPA) Relation name:? Attributes:? Domains of the attributes:? Degree: Spring 2002 CSC 742: DBMS by Dr. Peng Ning 7

Relation A relation r(r) is an instance of the corresponding relation schema R. Set of tuples of the form <v1... vn> Each tuple is an ordered list vi belongs to dom(ai) or is null thus vi is atomic: definition of 1NF Also called relation extension Spring 2002 CSC 742: DBMS by Dr. Peng Ning 8

A Mathematical Definition of Relation A relation r(r) is a mathematical relation of degree n of the domains dom(a1), dom(a2),, dom(an), which is a subset of the Cartesian product of the domains that define R: r(r) (dom(a1) dom(a2) dom(an)) Mind exercise: What is the number of all possible relations of R? Spring 2002 CSC 742: DBMS by Dr. Peng Ning 9

Achtung! The ordering of attributes is important mathematically, but not in practice tuples is not important mathematically, but is in practice Spring 2002 CSC 742: DBMS by Dr. Peng Ning 10

An Alternative Definition of Relation A relation schema R={A1, A2,, An} is a set of attributes. A relation r(r) is a finite set of mappings r={t1, t2,, tm}, where each ti is a mapping from R to D, D is the union of dom(ai) s, t[ai] must be in dom(ai). Each tuple can be considered as a set of attribute-value pairs. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 11

Notation Schemas: Q, R, S Instances: q, r, s Tuples: t, u, v t[ai] = vi, where t = <v1... vn> t[ai, Aj,... Ak] = <vi, vj,... vk> (subtuple) Spring 2002 CSC 742: DBMS by Dr. Peng Ning 12

Relational Databases A relational database schema is A set of relation schemas S={R1, R2,, Rm} and A set of integrity constraints IC. A relational database is a set of relations DB = {r1, r2,, rm} such that each ri is a relation of Ri, and ri satisfies the constraints in IC. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 13

Constraints Constraints that can specified on relational schemas. Domain constraints Key constraints Constraint about NULL Reference integrity constraints Spring 2002 CSC 742: DBMS by Dr. Peng Ning 14

Domain Constraints vi belongs to dom(ai) Domains map to standard data types Spring 2002 CSC 742: DBMS by Dr. Peng Ning 15

Key Constraints Superkey: subset of {Ai... An} that uniquely identifies R Key: minimal superkey Because r(r) must be sets, {Ai... An} is always a superkey Candidate key: key Primary key: any single key so designated Spring 2002 CSC 742: DBMS by Dr. Peng Ning 16

An Example Car LicenseNumber EngineSerialNumber Make Model Year Texas ABC-739 A691324 Ford Mustang 1996 Florida TVP-234 B43123123 Toyota Camery 2000 NC 341-1324 2HG32341235 Honda Civic 1998 Super Keys: Keys: Candidate Keys: Primary Key: Spring 2002 CSC 742: DBMS by Dr. Peng Ning 17

Entity Integrity Constraints No primary key attribute may be null Motivation: a violation would be analogous to an uninitialized object Spring 2002 CSC 742: DBMS by Dr. Peng Ning 18

Referential Integrity Constraints Specified on two relations Note that the previous constraints are on individual relations. Intuition If a tuple in one relation refers to a tuple in another relation, the second tuple should exist. Specified through foreign keys. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 19

Foreign Keys A set of attributes, FK in relation R1, is foreign key iff Attributes in FK occur as (primary) key in R2 FK reference or refer to the relation R2. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 20

An Example Driver Name SSN BirthDate Car Brown 123-45-6789 01/01/50 Texas ABC-739 Smith 222-33-4444 02/22/60 Florida TVP-234 John 444-55-6666 05/01/56 NC 341-1324 Car LicenseNumber EngineSerialNumber Make Model Year Texas ABC-739 A691324 Ford Mustang 1996 Florida TVP-234 B43123123 Toyota Camery 2000 NC 341-1324 2HG32341235 Honda Civic 1998 Spring 2002 CSC 742: DBMS by Dr. Peng Ning 21

Referential Integrity Constraints If t[fk] in r1 is all non-null, then u with u[fk]=t[fk] exists in r2 Motivation: a violation is analogous to a dangling pointer Spring 2002 CSC 742: DBMS by Dr. Peng Ning 22

Semantic Integrity Constraints Application-specific constraints typically involve restrictions on the values of an attribute with respect to some other attributes some varieties of them may be specified as assertions in SQL2 Spring 2002 CSC 742: DBMS by Dr. Peng Ning 23

General Strategy for Operations When legal, execute When illegal reject restore consistency (referential integrity) change referenced tuple (relation) change referencing tuple Spring 2002 CSC 742: DBMS by Dr. Peng Ning 24

Insert Insert <v1... vn> into R (means current instance) execute: just add it reject, e.g., when the key is already used Correct the problem Ask user to create referenced tuple or change the referencing tuple. Creating referenced tuple may be cascading. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 25

An Example Student Name StudentID Class Major Smith 17 1 CS Brown 8 2 CS Insert <John, N/A, 2, CS > <John, NULL, 2, CS > <John, 17, 2, CS > <John, 18, 2, CS > Spring 2002 CSC 742: DBMS by Dr. Peng Ning 26

Delete Delete <v1... vn> from R execute: remove reject, e.g., if other tuples refer to it Correct the problem cascade by deleting referring tuples change values to null or default Spring 2002 CSC 742: DBMS by Dr. Peng Ning 27

Modify As above Spring 2002 CSC 742: DBMS by Dr. Peng Ning 28

An Example Grade StudentID Course Grade 17 CSC 742 A Student 8 CSC 742 B+ Name StudentID Class Major Smith 17 1 CS Brown 8 2 CS Consider the following operations: Delete the 1 st tuple from Student. Insert <18, CSC742,, A- > into Grade Change StudentID of the 1 st tuple from 17 to 15. Options: reject, correct with cascade, correct by changing the values (set to NULL, or a valid value). Spring 2002 CSC 742: DBMS by Dr. Peng Ning 29